Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Correct way to pass a value back from a modal form?? 2

Status
Not open for further replies.

unclerico

IS-IT--Management
Jun 8, 2005
2,738
US
Access 2003

I'm wondering what the correct way to pass a value back from a modal form to the "parent" form would be?? Is the correct way to simply declare a global variable in a module?? I've seen ways to get a value from the "parent" form to the modal form, but not the other way around. thanks.
 
Save the value in an hidden TextBox in the "parent" form.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
thanks for replying so quickly. So, say I needed to pass 5 different values back from the modal form, would I create 5 different hidden text boxes or would I just build one long string, pass the value back and then maybe Split() the values out according to some delimiter?? Thanks again.
 
Another thing I do is use a public variable. ex

public myVariable as somedatatype

Then I make a function that when called pops up the form, sets the value of the variable, and then returns the variable.
ex

public function getMyVariable() as somedatatype
docmd.openform yourpopupform
'have the form set the variable when it closes
getmyVariable = myVariable
end function

Just be careful with using global variables. Do not over do them and scope them correctly.
 
MajP, I am not very clear on what you say and I apologize; I understand the usage of both the public variable as well as the function, but do you define these in a module or do you define one in a module and the other in a form?? Sorry, it has been a LOOONG time since I have done any coding in Access.
 
I put the function and the variable/s in a module. I use this technique if the value returned could be used in many different places. An example would be a pop up calendar which could be called from multiple forms

If the value/s will always return to just one specific form I simply define a public variable in the main form.

ex (main form called "Form1")
public myVar1 as variant
public myVar2 as variant

In the popup form then instead of setting a module global variable, I set the value of the public variable in the main form.

(pop up form)
Private Sub txtBxMaterial_AfterUpdate()
Form_Form1.myVar1 = txtBxMaterial.Value
End Sub

Conceptually similar to what PHV is suggesting, but instead of a hidden text box you are using a user defined variable. Both are properties of the form.
 
thank you both for giving me a badly needed nudge back in to the wonderful world of Access programming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top