How to create a modal Dialogue Box?

W

WDSnews

In Access, I wonder how to create a modal dialogue box that returns a value
to the calling form. I need my code to invoke a dialogue box in which the
user selects a name from a dropdown list, then exits the dialogue returning
the People.ID to the code which called it. I know how to do this in
ObjectPal. And in Access, I can build a small form with a combobox and two
buttons. I can write code to Open the second form on the screen. However,
what's the magic to...

....make the small form modal, like a dialogue box?
....suspend the first form's code until the modal box exits?
....return a People.ID to the calling form?
....and resume executing the first form's code?
 
F

fredg

In Access, I wonder how to create a modal dialogue box that returns a value
to the calling form. I need my code to invoke a dialogue box in which the
user selects a name from a dropdown list, then exits the dialogue returning
the People.ID to the code which called it. I know how to do this in
ObjectPal. And in Access, I can build a small form with a combobox and two
buttons. I can write code to Open the second form on the screen. However,
what's the magic to...

...make the small form modal, like a dialogue box?
...suspend the first form's code until the modal box exits?
...return a People.ID to the calling form?
...and resume executing the first form's code?

Open the dialog form in dialog.
Code will be suspended until the dialog form is made not visible using
a command button on that form, after which processing will continue.

' Open the form in dialog
DoCmd.OpenForm "DialogFormName", , , , , acDialog
' Read the control on that form after its command button is clicked
Me.PeopleID = forms!DialogFormName!ControlOnForm
' Close the dialog form
DoCmd.Close acForm, "DialogFormName"
 
J

Jeanette Cunningham

Hi WDSnews.
Open the dialog form in acDialog mode - this stops all code from executing
on the calling form.
DoCmd.OpenForm NameOfForm, WindowMode:=acDialog

The code behind the close or save button on the dialog form should not close
the form, but just make it invisible.
Once the dialog form is hidden, the code back on the calling form continues.
The next line of the calling form is to read the value it wants from the
hidden dialog form.
Then the calling form closes the hidden dialog form.
DoCmd.Close acForm, NameOfForm


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
A

Albert D. Kallal

WDSnews said:
In Access, I wonder how to create a modal dialogue box that returns a
value to the calling form. I need my code to invoke a dialogue box in
which the user selects a name from a dropdown list, then exits the
dialogue returning the People.ID to the code which called it. I know how
to do this in ObjectPal. And in Access, I can build a small form with a
combobox and two buttons. I can write code to Open the second form on the
screen. However, what's the magic to...

...make the small form modal, like a dialogue box?
...suspend the first form's code until the modal box exits?
...return a People.ID to the calling form?
...and resume executing the first form's code?

I explain step by step with code examples here:

http://www.members.shaw.ca/AlbertKallal/Dialog/Index.html
 
W

WDSnews

very helpful. thank you.


fredg said:
Open the dialog form in dialog.
Code will be suspended until the dialog form is made not visible using
a command button on that form, after which processing will continue.

' Open the form in dialog
DoCmd.OpenForm "DialogFormName", , , , , acDialog
' Read the control on that form after its command button is clicked
Me.PeopleID = forms!DialogFormName!ControlOnForm
' Close the dialog form
DoCmd.Close acForm, "DialogFormName"
 
W

WDSnews

I appreciate your help. Thank you.

Jeanette Cunningham said:
Hi WDSnews.
Open the dialog form in acDialog mode - this stops all code from executing
on the calling form.
DoCmd.OpenForm NameOfForm, WindowMode:=acDialog

The code behind the close or save button on the dialog form should not
close the form, but just make it invisible.
Once the dialog form is hidden, the code back on the calling form
continues.
The next line of the calling form is to read the value it wants from the
hidden dialog form.
Then the calling form closes the hidden dialog form.
DoCmd.Close acForm, NameOfForm


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top