IN THE SPOTLIGHT: MDE to MDB Conversion Service
(also supports: ACCDE to ACCDB, ADE to ADP, etc)
IN THE SPOTLIGHT: Access Database Repair Service
An in-depth repair service for corrupt Microsoft Access files
IN THE SPOTLIGHT: vbWatchdog
VBA error handling just got easier...
" vbWatchdog is off the chart. It solves a long standing problem of how to consolidate error handling into one global location and avoid repetitious code within applications. "
- Joe Anderson,
Microsoft Access MVP
Meet Shady, the vbWatchdog mascot watching over your VBA code →
(courtesy of Crystal Long, Microsoft Access MVP)
IN THE SPOTLIGHT: vbMAPI
An Outlook / MAPI code library for VBA, .NET and C# projects
Get emails out to your customers reliably, and without hassle, every single time.
Use vbMAPI alongside Microsoft Outlook to add professional emailing capabilities to your projects.
IN THE SPOTLIGHT: Code Protector
Standard compilation to MDE/ACCDE format is flawed and reversible.
Provided by allenbrowne.com, January 2004. Updated January 2008.
When you enter data into a form, Access saves the record automatically. An error message notifies you if the record cannot be saved. Or does it?
Use the Close action or method, and the form fails to notify you if the record cannot be saved. The form closes, and your entry is silently lost.
To demonstrate this flaw, download AccessFlaws.zip, open the form LosingData, and follow the instructions.
(Note: if you close the form with the [X] at the right end of the form's title bar, you do receive a warning that the record cannot be saved. Typically the problem occurs when you place a Close command button on your form.)
There are many reasons why a record could not be saved, such as:
Once you know the flaw exists, the solution is obvious. Never use Close without explicitly saving the record first:
If Me.Dirty Then Me.Dirty = False End If DoCmd.Close acForm, Me.Name
To force a record to be saved, you could use:
#1. RunCommand acCmdSaveRecord #2. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 #3. Me.Refresh #4. Me.Dirty = False
#1 fails if the form does not have focus.
#2 (as generated by the command button wizard in Access 95 to 2003) has the same problem, and also fails with pop-up forms in some versions.
#3 works, but older versions of Access do not generate a message if the save fails.
#4 specifies which form, and gives an error message if the save fails. The message may not be clear (e.g. "The property could not be set"), and the approach does not work in Access 1 or 2, but it is the most reliable approach unless you are working with the ancient versions.
This flaw exists in all versions of Access. It is very unlikely the issue will ever be fixed. Develop the habit of explicitly saving whenever you do anything that requires the record to be saved, e.g. applying or removing a Filter or OrderBy property, changing a RecordSource, or moving to another record.
In Access 2007, you can also avoid the problem if you use the Close action in a macro. You will also need to implement macro error handling (new in Access 2007.) The problem still occurs in Access 2007 if you use the Close method in VBA code. We recommend you explicitly save anyway.
The Microsoft knowledgebase demonstrates this bug has been known since version 2:
Home | Index of tips | Top |
Rate this article:
This is a cached tutorial, reproduced with permission.
iTech Masters | VAT: GB202994606 | Terms | Sitemap | Newsletter