ACC: Commands Not Available During BeforeUpdate EventLast reviewed: May 12, 1997Article ID: Q128195 |
The information in this article applies to:
SYMPTOMSAdvanced: Requires expert coding, interoperability, and multiuser skills. When you perform an action in the BeforeUpdate event, you receive the following error messages, even if you have canceled the event.
In Microsoft Access 7.0 and 97: - Runtime error '2105' You can't go to the specified record - Runtime error '2115' The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Access from saving the data in the field. In Microsoft Access 2.0: - Field or record can't be saved while it's being validated. - Command not available: UndoCurrentRecord. - Can't go to specified record. CAUSEMicrosoft Access cannot perform the specified command because the BeforeUpdate event procedure is still running. This is true even if the Cancel parameter is set to True or if a CancelEvent macro attempts to cancel the action. These error messages are generated by the following statements in the BeforeUpdate event procedure:
' Undo the current record. (Microsoft Access 2.0 only) ' NOTE: This behavior no longer occurs in Microsoft Access 7.0 and 97) DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, 1 ' Goto a new record. DoCmd.GoToRecord , , acNewRec '(Microsoft Access 7.0 and 97) DoCmd GoToRecord , , A_NEWREC '(Microsoft Access 2.0 ) ' Find a record DoCmd.FindRecord "Smith", , True, acAll, True '(Microsoft Access 7.0 and 97) DoCmd FindRecord "Smith", , True, A_ALL, True '(Microsoft Access 2.0) RESOLUTIONInstead of setting the Cancel parameter to True, or using the CancelEvent action, use a SendKeys statement if that is an option with the command you are trying to use. The SendKeys statement sends keystrokes to the Microsoft Access buffer, where they wait until the BeforeUpdate event procedure is finished.
MORE INFORMATIONTo go to a new record before the BeforeUpdate event procedure is finished, use the following code for the BeforeUpdate property's event procedure:
Sub Form_BeforeUpdate (Cancel As Integer) Dim Msg As String Msg = "Would you like to go to a new record?" If MsgBox(Msg, 32 + 4) = 6 Then ' SendKeys "%egw" '(for Microsoft Access 7.0 and 97) ' SendKeys "%rgw" '(for Microsoft Access 2.0) End If End SubNOTE: In some cases, you will need to include the CancelEvent action along with the SendKeys statement as in the following: To undo the current record (in Microsoft Access 2.0 only), in place of the following line to undo the current record
DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, 1use the SendKeys statement along with the CancelEvent action:
Docmd CancelEvent SendKeys "{ESC}{ESC}"To navigate to a new record, instead of the following code
DoCmd.GoToRecord , , acNewRec '(for Microsoft Access 7.0 and 97) DoCmd GoToRecord , , A_NEWREC '(for Microsoft Access 2.0)use the following SendKeys statement:
SendKeys "%egw" '(for Microsoft Access 7.0 and 97) SendKeys "%rgw" '(for Microsoft Access 2.0)For an additional example of how to use this technique, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q115189 TITLE : ACC2: How to Find a Record Using a Bound Control Steps to Reproduce Behavior
REFERENCESFor more information about SendKeys, search for "SendKeys Statement" using the Microsoft Access Help Index. |
Keywords : FmsEvnt kberrmsg kbusage
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |