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



The information in this article applies to:

  • Microsoft Access 97

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.

MORE INFORMATION

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.
  1. Create a new database in Access 97.
  2. Create a new, unbound form in design view.
  3. 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.
  4. Type ListMDBs for the RowSourceType of the ListBox.
  5. 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.
  6. Close and save the form as Form1.
  7. Create another unbound form in design view.
  8. Add one command button to the this form and name it Command0.
  9. 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
    					
  10. Close and save the form as Form2.
  11. 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.

Modification Type:MajorLast Reviewed:9/27/2003
Keywords:kbbug kbpending KB201962