ACC: Assigned Values Not Displayed When Form Opened As Dialog

Last reviewed: August 29, 1997
Article ID: Q109358
The information in this article applies to:
  • Microsoft Access versions 1.1, 2.0, 7.0, 97

SYMPTOMS

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

When you open a form as a dialog form using the OpenForm method or macro action, 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. Forms that are not opened as dialog forms allow you to set values for their controls.

MORE INFORMATION

Steps to Reproduce Behavior

The following example uses the OpenForm method in a Visual Basic procedure. The same results apply to using 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          : kbusage FmsEvnt
Version           : 1.0 1.1 2.0 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbprb
Solution Type     : Info_Provided


================================================================================


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