ACC: Assigned Values Not Displayed When Form Opened As Dialog
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 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 INFORMATIONSteps 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.
- Open the sample database Northwind.mdb (or NWIND.MDB in versions 1.1
and 2.0).
- 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.
- Save and close the form.
- Create a module and type the following line in the Declarations section
if it is not already there:
Option Explicit
- 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
- 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."
Additional query words:
Keywords : kbusage FmsEvnt
Version : WINDOWS:1.1,2.0,7.0,97
Platform : WINDOWS
Issue type : kbprb
|