Returning values from external Forms

D

Dennis

Hi,

I'm using Access via XP Office Pro.

I have a report that is calling a form that allows users to enter the
different options and parameters for the report (ie. Sort options, beginning
and ending dates, etc.). When the user is done entering their options and
click on the Generate Report (close) button, I hide the form. The report
closes the form when it is down.

Currently, I am returning the values via global variables. I also know that
I can reference the variables in my source query by using
Forms!FormName!VariableName.

Sometimes I use this technique if I have to call a form from within a form.

What is the best way for the form to return the values back to the report so
it can setup the appropriate SQL source statement?

I also have this same issue when my data entry form calls a "Add Reference
Info" form so the user can add a code and description. I would like the
reference form to return the value to my data entry form. I would then set my
data entry value to the value that was returned from my external form.



Thanks,

Dennis
 
J

Jack Leach

The generally accepted practice is to call the form in dialog windowmode, and
when the user is done with the form, rather than closing, use Me.Visible =
False to hide... the code after the calling line will then resume, at which
point you get the values from the hidden form, store them in a variable (not
global), and close the hidden form. Something like this:


Dim strVal As String
Dim lngVal As Long

DoCmd.OpenForm "ThisForm", , , , acDialog
strVal = Forms!ThisForm!ctlStringControl
lngVal = Forms!ThisForm!ctlLongControl
DoCmd.Close acForm, "ThisForm", acSaveNo



You can then use those variables in code/sql statements, whatever. I do
this for form operations often, though I don't see any reason you couldn't
make it work for report ops. Global variables used like this, for many
reasons, you generally want to avoid.

hth


--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
D

Dennis

Jack,

Thanks for the information. I see how to do it now.

Just out of curiosity, why should I not use global variables. I see a lot
of comments that say don't do it and I will respect the opinions of those who
know more than I do. But I would like to know why.

I appreciate any information you can provide. Thanks again.

Or maybe the more appropriate question is what is the appropriate way to use
a global variable.
 

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