PRB: IPF While Debugging Microsoft Access Automation Code

Last reviewed: March 13, 1998
Article ID: Q181888
The information in this article applies to:
  • Microsoft Visual Basic for Applications version 5.0
  • Microsoft Access versions 7.0, 97

SYMPTOMS

While debugging your code that uses Automation to control Microsoft Access, you may receive one of the following errors.

When automating Microsoft Access 95:

   MSACCESS caused an Invalid Page Fault in
   module MSACCESS.EXE at 0137:5000f878

   -or-

   MSACCESS caused an Invalid Page Fault in
   module KERNEL32.DLL at 0137:bff78040

When automating Microsoft Access 97:

   VB5 caused an invalid page fault in
   module OLEAUT32.DLL at 0137:65345949.

This problem only occurs when you run your code in Break mode (Debug mode).

CAUSE

The cause of the problem depends on the version of Microsoft Access that you are automating.

In Microsoft Access 95

When automating Microsoft Access 95, this problem may occur when all of the following conditions apply:

  • You run the code in Break mode.
  • You Dim a procedure-level Microsoft Access object variable.
  • You set this variable to reference a form or report in the database.
  • You do not set this variable to Nothing before ending the procedure.

The error occurs when you stop or reach the end the procedure and Microsoft Access attempts to quit. See the "More Information" section for an example and workaround.

Microsoft Access 97

When automating Microsoft Access 97, this problem may occur when all of the following conditions apply:

  • You run the code in Break mode.
  • You Dim a procedure-level Microsoft Access object variable as Access.Form or Access.Report.
  • You set this variable to reference a form or report in the database.

The error occurs when you reference the form or report variable. See the "More Information" section for an example and workaround.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The following examples show how to reproduce this problem under each version of Microsoft Access. A workaround is provided for each example.

Microsoft Access 95

   Sub TestAccess95()
      Dim objAccess As Object
      Dim objForm As Object
      Set objAccess = CreateObject("Access.Application")
      objAccess.Visible = True
      objAccess.OpenCurrentDatabase _
         objAccess.SysCmd(acSysCmdAccessDir) & "Samples\Northwind.mdb"
      objAccess.DoCmd.OpenForm "Employees"
      Set objForm = objAccess.Forms("Employees")
      objAccess.DoCmd.Close acForm, "Employees"
      Stop 'Enters Break Mode, pausing code execution
   End Sub

You should establish a reference to the "Microsoft Access for Windows 95" library in your project before running the code. When you run this procedure and get to the Stop statement, which enters Break mode, switch over to Microsoft Access and close the startup form if it is open. Then switch back to your code and press F8 to continue past the Stop statement and again past the End Sub.

Result: Microsoft Access will close automatically because the object variables lose scope and no forms and reports are open in the database. This is by design. However, you then receive an Invalid Page Fault error.

Workaround:

Set all procedure-level form and report object variables to Nothing before ending the procedure. For this example, add the following lines at the end of the procedure:

   Set objForm = Nothing
   Set objAccess = Nothing

Microsoft Access 97

   Sub TestAccess97()
      Dim objAccess As Access.Application
      Dim objForm As Access.Form
      Set objAccess = CreateObject("Access.Application")
      objAccess.Visible = True
      objAccess.OpenCurrentDatabase _
         objAccess.SysCmd(acSysCmdAccessDir) & "Samples\Northwind.mdb"
      objAccess.DoCmd.OpenForm "Employees"
      Set objForm = objAccess.Forms("Employees")
      Stop 'Enters Break Mode, pausing code execution
      MsgBox objForm.Name
   End Sub

Be sure to establish a reference to the "Microsoft Access 8.0 Object Library" in your project before running the code. When you run this procedure and get to the Stop statement, which enters Break mode, press F8 to continue to the MsgBox line.

Result: An Invalid Page Fault error occurs, causing the client application to terminate.

Workaround:

Dim all procedure-level form and report object variables as Object. For this example, Dim objForm as Object instead of Access.Form. Another workaround is to Dim the variable as Access.Form at the module level.

REFERENCES

For additional information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q147816
   TITLE     : ACC: Using Microsoft Access as an Automation Server

   ARTICLE-ID: Q167223
   TITLE     : Microsoft Office 97 Automation Help File Available on MSL


Additional query words: access violation gpf crash
Keywords : kberrmsg kbdta offinterop VBKBAutomation
Technology : ole
Version : WINDOWS:5.0,7.0,97
Platform : WINDOWS
Issue type : kbprb


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: March 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.