Microsoft KB Archive/275102

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

Article ID: 275102

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



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
 Start Access 2000 and create a new blank database. Create a new form in Design view.  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  Compile and save the VBA project.

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

You should receive the run-time error message from the divide-by-zero error.</li> Click End to stop the code.</li> Close all objects and make sure that the project is still compiled.</li> Close the database in Access 2000 and re-open the database in Access 2002.</li> 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.</li></ol>

<div class="references_section">