Microsoft Knowledge Base Email Alertz

(128195) - 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: -...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 128195 - Last Review: January 19, 2007 - Revision: 2.1

ACC: Commands Not Available During BeforeUpdate Event

This article was previously published under Q128195

On This Page

SYMPTOMS

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.

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.

CAUSE

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)

RESOLUTION

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.

MORE INFORMATION

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
				

NOTE: 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, 1
				

use 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:

115189  (http://kbalertz.com/Feedback.aspx?kbNumber=115189/EN-US/ ) ACC2: How to Find a Record Using a Bound Control

Steps to Reproduce Behavior


  1. Open the sample database Northwind.mdb (or NWIND.MDB in Microsoft Access 2.0).
  2. Open the Customers form in Design view.
  3. Set the form's BeforeUpdate property to the following 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
                 ' 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
    						
  4. View the form in Form view.
  5. Change the data in any field, and then click Save Record on the Records menu.
  6. When you are prompted "Would you like to go to a new record?" click Yes. Note that you receive the following error message.

    In Microsoft Access 7.0 and 97:
    Runtime error '2105'
    You can't go to the specified record
    In Microsoft Access 2.0:
    Can't go to specified record

REFERENCES

For more information about SendKeys, search for "SendKeys Statement" using the Microsoft Access Help Index.

APPLIES TO
  • Microsoft Access 2.0 Standard Edition
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition
Keywords: 
kberrmsg kbprb kbusage KB128195
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Jeffrey Ross Report As Irrelevant  
Written: 6/3/2008 7:55 PM
That was so very useful. I have no training in Access and stumble through writing code. I was stuck on acceptable syntax to create a new record because I was using parentheses. When I did the same thing without the parentheses it worked, just like your example shows: DoCmd.GoToRecord , , acNewRec Thanks