ACC: Edits Not Processed with Close Action on Form (131813)
The information in this article applies to:
- Microsoft Access 2.0
- Microsoft Access for Windows 95 7.0
- Microsoft Access 97
This article was previously published under Q131813
Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
When you edit a record in a form, the editing changes are not processed
when the form is closed with a macro's Close action. However, you are not
prompted with any error messages as to why the changes are not saved.
CAUSE
The Close action is invoked with the DoCmd method in Visual Basic for
Applications (or the DoCmd statement in Access Basic in Microsoft Access
2.0) and the current record is not processed because a validation error has
occurred. The following validation errors can prevent editing changes from
being processed when the form closes:
- A validation rule violation.
- A primary key or index violation.
- A referential integrity violation.
RESOLUTION
To work around this problem, force the record to be saved before the Close
action is run by using the following RunCommand method (or DoMenuItem
method in Microsoft Access 2.0 and 7.0) to select Save Record on the
Records menu (or File menu in Microsoft Access 2.0).
In Microsoft Access 97
DoCmd.RunCommand acCmdSaveRecord
NOTE: In Microsoft Access 97, the DoMenuItem method has been replaced by
the RunCommand method. The DoMenuItem method is included in Microsoft
Access 97 only for compatibility with earlier versions.
In Microsoft Access 7.0
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord,, acMenuVer70
In Microsoft Access 2.0
DoCmd DoMenuItem A_FormBar, A_File, A_SaveRecord, , A_Menu_Ver20
For example, if you choose the Command Button Wizard to create a Close
button on a form, the following Visual Basic (or Access Basic in Microsoft
Access 2.0) Sub procedure is generated.
In Microsoft Access 7.0 and 97
Private Sub CloseForm_Click()
On Error GoTo Err_CloseForm_Click
DoCmd.Close
Exit_CloseForm_Click:
Exit Sub
Err_CloseForm_Click:
MsgBox Err.Description
Resume Exit_CloseForm_Click
End Sub
In Microsoft Access 2.0
Sub CloseForm_Click ()
On Error GoTo Err_CloseForm_Click
DoCmd Close
Exit_CloseForm_Click:
Exit Sub
Err_CloseForm_Click:
MsgBox Error$
Resume Exit_CloseForm_Click
End Sub
To force a record to be saved before the Close action is run, insert the
RunCommand method (or DoMenuItem method) immediately before the DoCmd Close
line in the Sub procedure. This will cause Microsoft Access to prompt you
with a message as to why the record cannot be saved.
Also, use the On Error GoTo statement to trap any error that may occur.
STATUS
Microsoft has confirmed this to be a problem in Microsoft Access versions
2.0, 7.0, and 97. We are researching this problem and will post new
information here in the Microsoft Knowledge Base as it becomes available.
REFERENCES
For more information about the Close action, search the Help Index for
"Close action," or ask the Microsoft Access 97 Office Assistant.
Modification Type: | Major | Last Reviewed: | 5/7/2003 |
---|
Keywords: | kbbug kbusage KB131813 |
---|
|