ACC2: "Invalid Reference" Saving Record on Form with Button

Last reviewed: July 11, 1997
Article ID: Q123858
The information in this article applies to:
  • Microsoft Access version 2.0

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you try to save a record by choosing a command button on a form that runs a DoMenuItem action, you receive the following error message:

   Invalid reference to field 'Form_BeforeUpdate'

CAUSE

The Cancel argument is being set in the form's BeforeUpdate event procedure.

RESOLUTION

There are two ways to work around this problem. The first method traps and handles the error, and the second cancels the event in a different manner.

Method 1

You can work around the problem by trapping and handling the error message. When you execute the DoMenuItem action to save the record, trap for error 2465 and replace it with a more descriptive error message. For example, you could attach the following sample Access Basic code to the command button:

   Sub Button1_Click ()
      On Error GoTo Err_Button1_Click
         DoCmd DoMenuItem A_FORMBAR, A_FILE, A_SAVERECORD, , A_MENU_VER20
      Exit_Button1_Click:
         Exit Sub
      Err_Button1_Click:
         Select Case Err
            Case 2465
               MsgBox "Descriptive error message of your choice here"
            Case Else
               MsgBox Error$
         End Select
         Resume Exit_Button1_Click
   End Sub

Method 2

In step 5 of the example in the "Steps to Reproduce Problem" section below, use

   DoCmd CancelEvent

instead of:

   Cancel = True

STATUS

Microsoft has confirmed this to be a problem in Microsoft Access version 2.0. This problem no longer occurs in Microsoft Access version 7.0.

MORE INFORMATION

The problem described above usually results in the error message "Invalid reference to 'Form_BeforeUpdate'," but may also result in the error message "Invalid reference to field 'Button0_Click'."

This problem can also occur if you call a macro instead of code in the BeforeUpdate property. The only method of saving a record that works as you expect is choosing Save Record from the File menu.

Steps to Reproduce Problem

  1. Start Microsoft Access and open the sample database NWIND.MDB.

  2. Create a new form based on the Employees table. Set the form's DefaultView property to Single Form.

  3. Add a text box control to the form. Set the text box's ControlSource property to First Name.

  4. Create a Save Record button using the Command Button Wizard. To create this button, follow these steps:

        a. Choose the Control Wizards button in the toolbox (the button should
           appear sunken).
    

        b. Add a command button to the form.
    

        c. In the Categories box, select Record Operations. In the When Button
           Is Pressed box, select Save Record. Choose the Next button.
    

        d. Choose the Next button, then choose the Finish button.
    

  5. Set the form's BeforeUpdate property to the following event procedure:

          Sub Form_BeforeUpdate (Cancel As Integer)
             Cancel = True
          End Sub
    
    

  6. View the form in Form view and enter any text in the text box.

  7. Choose the command button to save the record. You receive the error message stated above.


Keywords : FmsProb kberrmsg kbusage
Version : 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbbug
Resolution Type : kbcode


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 11, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.