Microsoft KB Archive/109358

From BetaArchive Wiki

Article ID: 109358

Article Last Modified on 1/18/2007



APPLIES TO

  • Microsoft Access 1.1 Standard Edition
  • Microsoft Access 2.0 Standard Edition
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition



This article was previously published under Q109358

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

SYMPTOMS

When you use the OpenForm method or macro action to open a form as a dialog form, fields on the form do not display the values that you assign to them.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.

CAUSE

This occurs because dialog forms are modal, and Microsoft Access suspends code execution until the dialog form is closed. After the form is closed, you cannot set values for any of its controls.

MORE INFORMATION

Steps to Reproduce Behavior

The following example uses the OpenForm method in a Visual Basic procedure to reproduce the behavior. You get the same results if you use the OpenForm action in a macro.

  1. Open the sample database Northwind.mdb (or NWIND.MDB in versions 1.1 and 2.0).
  2. Create a new form called Form1. Add a text box control to the form and set its Name property (or ControlName property in version 1.1) to Field0.
  3. Save and close the form.
  4. Create a module and type the following line in the Declarations section if it is not already there:

    Option Explicit

  5. Type the following procedure:

    In Microsoft Access 7.0 and 97:

          Function TestModal()
             DoCmd.OpenForm "Form1", acNormal, "", "", acEdit, acDialog
             Forms!Form1!Field0 = "Hello"
          End Function
                            

    In Microsoft Access 1.1 and 2.0:

          Function TestModal()
             DoCmd OpenForm "Form1", A_NORMAL, "", "", A_EDIT, A_DIALOG
             Forms!Form1!Field0 = "Hello"
          End Function
                            
  6. To test this function, type the following line in the Debug window (or the Immediate window in versions 1.1 and 2.0), and then press ENTER:

    ?TestModal()

    Note that when the form opens, the text box does not display any text. Also, when you close the form you receive an error because the procedure continues to run, and the Field0 text box is no longer available to have its value set.

    If you change acDialog (or A_DIALOG in versions 1.1 and 2.0) to acNormal (or A_NORMAL in versions 1.1 and 2.0) in step 5, and then run the procedure again, the text box displays the word "Hello."


REFERENCES

For more information about opening forms as dialog forms in Microsoft Access, search the Help Index for "modal forms."

Keywords: kbprb kbprogramming kbusage KB109358