Basic question about passing variables

April15Hater

Accountant
Local time
Today, 03:01
Joined
Sep 12, 2008
Messages
349
Hi-

I have a pretty basic question that would save me a bunch of time. Right now I have a form button (Forms!frmStep5b!cmdOverride) that opens another form:

DoCmd.OpenForm "frmOverrride", , , , ACDialog

I know I can use OpenArgs to pass a variable from frmStep5b to frmOverrride. However I'd like to be able to pass a value in the reverse: frmOverride to frmStep5. Is such a thing possible or am I going to have to resort to public variables?

Thanks,

Joe
 
A roundabout manner of doing this would be to:

1) Create a standard module.
2) Write a public function that will return the variable what you want it to return.
3) Within the public function body, call a OpenForm to a dialog form (the form should be a lightweight form, meaning it has its HasModule property set to no.)
4) For all buttons or whatever it uses (or just the Close event if so preferred), call another function in the same module. This function's job would be only to receive the values, store it in a private variable and then close the form.
5) The original function would then get the private variable and return it to the caller.

There may be a better way of doing this, and you may be able to get away with more straightforward manner (e.g. hardcoding the return value to a specific form control for example) if you do not need it to be flexible and work for any form.

Hope that helps.
 
Joe,

Just put it directly on frmStep5 (if you can).

If frmStep5 will be open, it should be as simple as:

Forms!frmStep5!SomeField = Me.SomeOtherField

Otherwise, store it in a table. Very nice when resuming sessions.

Or lastly, use a Public Variable, it won't persist. And as Banana
has shown, you'll need to use it in a Public Function if you want
to reference it in a query.

hth,
Wayne
 
Hey guys-

Thanks for the responses. I think I'm just going to use a public variable even though I hate using them. I was just hoping there was a way to do something like myVar = docmd.openform('Frm", , , , ACDialog), a reverse openargs if you will. Thanks again!

Joe
 

Users who are viewing this thread

Back
Top Bottom