Microsoft KB Archive/201962

= ACC97: Fatal Error When You Use Code to Open Non-Default Instance of Form =

Article ID: 201962

Article Last Modified on 1/23/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q201962



Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you use code behind a command button to open a non-default instance of a form, a fatal error may result if the form being opened contains a list box or combo box that is populated by using a function instead of a value list, field list, or table/query. The error message varies, according to the operating system of the computer.

Microsoft Windows 95, Microsoft Windows 98, or Microsoft Windows Millennium Edition (Me):
This program has performed an illegal operation and will be shut down.

If the problem persists, contact the program vendor.

When you click Details (on Microsoft Windows Millennium Edition, press ALT+D), you receive the following message:

The instruction at 0x00000000 caused an invalid page fault in MSAccess.exe 97 at 0x00000000. The memory could not be 'read'.

NOTE: The actual memory address may vary.

Microsoft Windows NT:
An application error has occurred and an application error log is being generated.

Exception: access violation (Exception:access violation (0xc0000005), address:Address 0x00000008)

Microsoft Windows 2000:
The instruction at "0x00000000' referenced memory at "0x00000000". The memory could not be "read".

The program shuts down whether you click OK or Cancel.



CAUSE
This problem occurs when you use a non-default (instantiated) instance of a form. When a function included in the form module is used to set the RowSourceType property of a list box or combo box on the instantiated instance of a form, a fatal error occurs in Msaccess.exe.

The problem does not occur on the default (or normal) instance of a form or when the function is moved to a standard module.



RESOLUTION
To work around this problem, use one of the following methods:  Move the code that populates the list box or combo box from the form module to a standard module.  Use the following code to open the form: Private Sub Command0_Click DoCmd.OpenForm "form1" End Sub 



STATUS
Microsoft has confirmed that this is a problem in Microsoft Access 97.



Steps to Reproduce Problem
WARNING: Following these steps will cause a fatal error on your computer. Make sure you save and close any open work on your computer before you follow these steps.  Create a new database in Access 97. Create a new, unbound form in design view.</li> Add an unbound ListBox to the form.

NOTE: This also fails with a ComboBox. To reproduce, follow the same steps, adding a ComboBox instead of a ListBox.</li> Type ListMDBs for the RowSourceType of the ListBox.</li>  Type the following code in the form's module: Function ListMDBs(fld As Control, id As Variant, row As Variant, _              col As Variant, code As Variant) As Variant

Static dbs(127) As String, Entries As Integer Dim ReturnVal As Variant

ReturnVal = Null

Select Case code

Case acLBInitialize        ' Initialize. Entries = 0 dbs(Entries) = Dir("*.MDB")

Do Until dbs(Entries) = "" Or Entries >= 127 Entries = Entries + 1 dbs(Entries) = Dir Loop ReturnVal = Entries

Case acLBOpen              ' Open. ReturnVal = Timer    ' Generate unique ID for control. Case acLBGetRowCount       ' Get number of rows. ReturnVal = Entries Case acLBGetColumnCount    ' Get number of columns. ReturnVal = 1 Case acLBGetColumnWidth    ' Column width. ReturnVal = -1        ' -1 forces use of default width. Case acLBGetValue          ' Get data. ReturnVal = dbs(row) Case acLBEnd               ' End. Erase dbs End Select

ListMDBs = ReturnVal

End Function NOTE: You can find this code sample in Access Help by searching the index for the RowSourceType property. Select the topic "Create a list box or combo box that gets its rows from a function", and then click the button in step 1.

When the form opens, it populates the ListBox with a list of all Access databases in the current directory. </li> Close and save the form as Form1.</li> Create another unbound form in design view.</li> Add one command button to the this form and name it Command0.</li>  Add the following code to the form's module: Dim NewFrm As Form Private Sub Command0_Click Set NewFrm = New Form_Form1 NewFrm.SetFocus End Sub </li> Close and save the form as Form2.</li> Open Form2 and click the command button. Note that a fatal error as described in the "Symptoms" section of this article occurs in Msaccess.exe.</li></ol>

Additional query words: pra forms crashed crashes crashing shutdown gpf ipf dr watson drwtsn drwatson msaccess

Keywords: kbbug kbpending KB201962

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.