ACC: Commands Not Available During BeforeUpdate EventID: Q128195
|
Advanced: 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.
- Field or record can't be saved while it's being validated.
- Command not available: UndoCurrentRecord.
- Can't go to specified record.
Microsoft 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)
Instead 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.
To 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 Sub
DoCmd DoMenuItem A_FORMBAR, A_EDITMENU, 1
Docmd CancelEvent
SendKeys "{ESC}{ESC}"
DoCmd.GoToRecord , , acNewRec '(for Microsoft Access 7.0 and 97)
DoCmd GoToRecord , , A_NEWREC '(for Microsoft Access 2.0)
SendKeys "%egw" '(for Microsoft Access 7.0 and 97)
SendKeys "%rgw" '(for Microsoft Access 2.0)
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
' User chose Yes so undo the current record.
DoCmd.GoToRecord , , acNewRec '(for Microsoft Access 97 only)
' In Microsoft Access 2.0 use the following line instead:
' DoCmd GoToRecord , , A_NEWREC
End If
End Sub
In Microsoft Access 2.0:Runtime error '2105'
You can't go to the specified record
Can't go to specified record
For more information about SendKeys, search for "SendKeys Statement" using the Microsoft Access Help Index.
Keywords : kberrmsg kbusage FmsEvnt
Version : 2.0 7.0 97
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 9, 1999