ACC2002: Microsoft Access Quits When You Programmatically Switch Views on Open Tables or Queries (295242)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q295242
Novice: Requires knowledge of the user interface on single-user computers.

This article applies only to a Microsoft Access database (.mdb).

SYMPTOMS

When you use Visual Basic for Applications (VBA) code to switch between views on open tables or queries, you may receive the following error message, and then Microsoft Access quits:
Microsoft Access has encountered a problem and needs to close. We are sorry for the inconvenience.
When you view the details in the error report, the report states that an error has occurred in Msaccess.exe.

CAUSE

You receive the error message if the table or query is currently open.

RESOLUTION

If you must change the view of the table or query, you must modify your code to first close the open table or query, and then reopen the table or query for the view that you want.

For the example in the "Steps to Reproduce the Behavior" section later in this article, you can change the code and correct the behavior as follows:
  1. For the Customer Table in Print Preview command button, make the following code changes:
    DoCmd.Close acTable, "customers"
    DoCmd.OpenTable "Customers", acViewPreview
  2. For the Switch Customer Table to Design View command button, make the following code changes:
    DoCmd.Close acTable, "customers"
    DoCmd.OpenTable "Customers", acViewDesign

STATUS

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

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In the Northwind sample database, create a new form.
  2. Add a command button to the form, and then set the following properties:
       Command button
       --------------
       Name: Command1
       Caption: Customer Table in Print Preview
       OnClick: [Event Procedure]
  3. Set the OnClick property of the Command1 command button to the following event procedure:
    DoCmd.OpenTable "Customers", acViewPreview
    					
  4. Add another command button to the form, and then set following properties:
       Command button
       --------------
       Name: Command2
       Caption: Switch Customer Table to Design View
       OnClick: [Event Procedure]
    					
  5. Set the OnClick property of the Command2 command button to the following event procedure:
    DoCmd.OpenTable "Customers", acViewDesign
  6. Save the form as Form1.
  7. Open the Form1 form, and then click the Customer Table in Print Preview button.
  8. Switch back to the form without closing the preview of the Customers table, and then click the Switch Customer Table to Design View button.

    Note that you receive the error message that is mentioned in the "Symptoms" section of this article, and then Microsoft Access quits.

Modification Type:MajorLast Reviewed:9/25/2003
Keywords:kbbug kberrmsg kbnofix KB295242