How do I obtain a value from an external form?

D

Dennis

Hi,

I'm on Access via XP Office Pro.


How do I obtain values from an form that I run using the DoCmd.OpenForm.

Currently, I have the form opened by OpenForm setting values in global
variables. I have a standard set of global variables that are set by the
called form and retreived in the calling form (the one that ran the DoCmd).

I've read where I should not be using global variables.

For example, on my customer call log form, we record all of our incoming
calls as they happen. If one of those calls results in the creation of a
work order, I want to click on the Work Order button, have the work order
screen pop up, enter the work order information, and the have the work order
number returned to the call log form so I can put the work order number on
the call log row.

I also all the user to add item to the drop down list by double clicking on
the field. This causes the program to lauch the Add/Chg Form for the code.
The user can than add a new code to the table. I return this value back to
the data entry screen the combo box is set to this value when the user
returns to the data entry screen. This value is also returned via a global
variable.

What is the best or most appropriate way to return the variable from a
DoCmd.OpenForm form?

I've see where I set the variable in the external form. When the user
"closes" the external form, I should hide the form and then having the
calling program extract the variable from the form by using
Forms!ExternalFormNm!ControlName, and then have the calling form close the
close form.

The main problem I see with this approach is I have tightly coupled my
calling forms to my called form. If I ever change the form name or change
the control name, I have to go through all of my code and change it to
reflect the new names.

Any suggestions?

Thanks,
 
D

Daryl S

Dennis -

One way to do this is to use the OpenArgs on the OpenForm Method. This lets
you pass in a variable to the called form. You can pass in the name of the
calling form (or if you need to, pass in the calling form and control name
where you want the key value to go to).

Then in the called form, you need to look to see if the OpenArgs is
populated. You can do this when the form is closed - if the user entered a
new record and there is an OpenArgs passed in, then put the new key value
back on the calling form, using the OpenArgs to know which form that is.
 
D

Dennis

Hi Daryl,

I do pass parms into the form using OpenArgs that I open using the OpenForm
method.

With respect to your comment

"Then in the called form, you need to look to see if the OpenArgs is
populated. You can do this when the form is closed - if the user entered a
new record and there is an OpenArgs passed in, then put the new key value
back on the calling form, using the OpenArgs to know which form that is."


How would you do that above?


Dennis
 
D

Daryl S

Dennis -

In the second (called) form, you want code like this in the Form's Close
event:

Dim CallingFormName As String
CallingFormName = Me.OpenArgs 'calling form name passed in

If Len(CallingFormName) > 0 Then
DoCmd.OpenForm CallingFormName 'Open the form that called this form.
End If
 

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