ACC: Edits Not Processed w/ Close Action on Form (2.0, 7.0, 97)Last reviewed: July 21, 1997Article ID: Q131813 |
The information in this article applies to:
SYMPTOMSModerate: Requires basic macro, coding, and interoperability skills. 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.
CAUSEThe 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:
RESOLUTIONTo 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_Ver20For 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 SubTo 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.
STATUSMicrosoft 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.
MORE INFORMATION
Steps to Reproduce Problem
In Microsoft Access 7.0 and 97
In Microsoft Access 2.0
REFERENCESFor more information about the Close action, search the Help Index for "Close action," or ask the Microsoft Access 97 Office Assistant. |
Keywords : kbusage McrProb
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |