OpenForm

G

Gary D.

I am using the following syntax to open a form (custom dialog pop-up):

DoCmd.OpenForm "formname", acNormal, , , acReadOnly, acDialog,
"openargs"

This works fine.

What I would like to do is return a value from the open form when a
user clicks a button.

Can this be done using the above approach?
If not, what are the alternatives?

Thanks.
 
A

Allen Browne

Return where?

If you want to assign the value to a text box on a form that is still open
in the background:
Forms("Form1").Controls("Text0") = "This is the value I want to see."

Alternatively, you could assign a value to a public variable.

For an example, see:
Popup calendar
at:
http://allenbrowne.com/ser-51.html
The pop-up calendar is an Access form, and it assigns the return value to
whichever text box calls it by using a public variable reference to the text
box.
 
R

Rick Brandt

Gary said:
I am using the following syntax to open a form (custom dialog pop-up):

DoCmd.OpenForm "formname", acNormal, , , acReadOnly, acDialog,
"openargs"

This works fine.

What I would like to do is return a value from the open form when a
user clicks a button.

Can this be done using the above approach?
If not, what are the alternatives?

Thanks.

You can either "push" or "pull". The dialog form can use code to push values
from its controls into controls on the calling form in its close or unload
event.

Forms!CallingFormName!ControlName = Me!ControlName

Alternatively, you can set values on the dialog form and have its [close] or
[ok] button only hide the form rather than close it. Then the code in the
calling form can pull values from it and then close it.

DoCmd.OpenForm "formname", acNormal, , , acReadOnly, acDialog, "openargs"
Me!ControlName = Forms!DialogFormName!ControlName
DoCmd.Close acForm, DialogFormName

The above works because hiding the dialog form will cause the calling code to
commence running the same way that closing it does.
 
G

Gary D.

Return where?

If you want to assign the value to a text box on a form that is still open
in the background:

No, there is no other form open.

I am enhancing a utility library (mde) of common functions.

A module/function opens the pop-up form to display a count-down, using
OpenArgs to set the count-down period, e.g. 10 seconds. When the
count-down time has reduced to zero the form closes itself.
However, the form has OK and Cancel buttons - if a user clicks on
either of these I wanted to identify which button was clicked.

I'm using the function/form as a user-friendly way of offering the
option to interrupt further processing in other applications.

I've now managed to achieve the desired effect using a global/public
variable to return the key code value. I don't like using global
variables if it can be avoided, but in this case I couldn't see
another way around it. At least it works!
 
Top