Error messages do not appear when you use Visual Basic for Applications code to run a procedure in an Access 2002 database (275102)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q275102
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SYMPTOMS

When you use Microsoft Visual Basic for Applications (VBA) code to run a procedure in a Microsoft Access 2002 database, the code does not return an error message or stop running as you expect. This problem occurs when the procedure contains an unhandled error, the Err.Raise statement, or the Stop statement.

CAUSE

This problem occurs because the database is compiled by Access 2002 and still contains the Access 2000 object library information. VBA cannot enter break mode until VBA first decompiles the VBA project and then references the object library information for the current version of Access.

RESOLUTION

With the database open in Access 2002, open the Visual Basic Editor. This action decompiles the VBA project and references the Access 2002 object library information.

MORE INFORMATION

When a database's VBA project is compiled, the current object library (Access 2000 or Access 2002) is stored as part of the compiled project. Access 2002 can run code in a compiled Access 2000 project. However, Access 2002 cannot enter break mode unless the project is first decompiled. Therefore, the Err.Raise statement and the Stop statement do not appear as you expect. Also, there are no unhandled error messages.

Steps to reproduce the problem

  1. Start Access 2000 and create a new blank database.
  2. Create a new form in Design view.
  3. Place the following code behind the form's Open event in the Visual Basic Editor:
    Private Sub Form_Open(Cancel As Integer)
        Dim iResult As Integer
    
        'Force an unhandled divide by zero error
        iResult = 1/0
    End Sub
    					
  4. Compile and save the VBA project.

    This step is required to reproduce the problem.
  5. Open the form in Form view.

    You should receive the run-time error message from the divide-by-zero error.
  6. Click End to stop the code.
  7. Close all objects and make sure that the project is still compiled.
  8. Close the database in Access 2000 and re-open the database in Access 2002.
  9. Open the form in Form view. Notice that the form does not open and you do not receive the error message from the divide-by-zero error.

REFERENCES

For more information about handling errors at run-time, click Microsoft Visual Basic Help on the Help menu, type handling errors in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbprb KB275102