Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Access 2000 Unexpectedly Quits When You Run Code to Open an Object


View products that this article applies to.

This article was previously published under Q323203
Moderate: Requires basic macro, coding, and interoperability skills.

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

↑ Back to the top


Symptoms

When you run Microsoft Visual Basic for Applications code to open an object, the database unexpectedly quits. Additionally, you may receive a Dr. Watson message or a different error message that says that the database has performed an illegal function and will be shut down.

↑ Back to the top


Cause

The database was created in Microsoft Access 2002, but the database is now in the Access 2000 file format, and you are working in Access 2000.

↑ Back to the top


Resolution

To resolve this issue, refresh the references. You can either refresh the references manually or you can use code to refresh the references.

Refreshing the References Manually

  1. Open the database that you are working with.
  2. In the Database window, click Modules under Objects.
  3. If there is already a module there, open it in Design view. If you do not have any modules in your database yet, click New.
  4. In the Visual Basic Editor, click References on the Tools menu.
  5. Click to select any reference that is not already selected. Remember the name of the reference, and then click OK.
  6. On the Tools menu, click References.
  7. Click to clear the reference that you selected in step 5, and then click OK.
  8. On the File menu, click Close and Return to Microsoft Access.
Now you can run the code that previously caused Access to quit.

Using Code to Refresh the References

To use code to refresh the references, create the following command button on a form:
  1. In the Database window, click Forms under Objects, and then click New.
  2. Click Design View, and then click OK.
  3. If the toolbox is not visible, click Toolbox on the View menu.
  4. Add a command button to the form.
  5. If the Properties dialog box is not visible, click Properties on the View menu.
  6. Click the Event tab, click the On Click property, click the down arrow, click [Event Procedure], and then click the Build (...) button.
  7. Type or paste the following code in the subroutine:
    Dim r As Reference, r1 As Reference
    Dim s As String
    
    ' Look for the first reference in the database other
    ' than Access and Visual Basic for Applications.
    For Each r In Application.References
       If r.Name <> "Access" And r.Name <> "VBA" Then
          Set r1 = r
          Exit For
       End If
    Next
    s = r1.FullPath
    
    ' Remove the Reference and add it back.
    References.Remove r1
    References.AddFromFile s
    
    ' Call a hidden SysCmd to automatically compile and save all modules.
    Call SysCmd(504, 16483)
    					
  8. On the File menu, click Close and Return to Microsoft Access.
  9. Close the form and save the change.
When you want to reset the references, open the form, and then click the command button.

NOTE: If the database is part of a replica set, you must apply this code to the Design Master. Then, run the code when the project component of the database (for example, forms, reports, and modules) is changed. Finally, synchronize the database with the replica.

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

The code that opens the object may be similar to the following:
Docmd.Openform "<formname>"
				
-or-
DoCmd.OpenReport "<reportname>"
				

↑ Back to the top


Keywords: KB323203, kbnofix, kbbug

↑ Back to the top

Article Info
Article ID : 323203
Revision : 2
Created on : 6/25/2004
Published on : 6/25/2004
Exists online : False
Views : 266