ACC2000: Assigned Values Not Displayed When Form Opened As Dialog

ID: Q210461


The information in this article applies to:


SYMPTOMS

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

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.


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.


  2. Create a new form called Form1. Add a text box control to the form and set its Name property 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:


  5. 
    Option Explicit 
  6. Type the following procedure:


  7. 
    Function TestModal()
       DoCmd.OpenForm "Form1", acNormal, "", "", acFormEdit, acDialog
       Forms!Form1!Field0 = "Hello"
    End Function 
  8. To test this function, type the following line in the Immediate window, 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.


Additional query words: prb


Keywords          : kbusage kbdta FmsEvnt 
Version           : WINDOWS:2000
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: May 13, 1999