Passing variable from modal form to main form

crowegreg

Registered User.
Local time
Today, 14:09
Joined
Feb 28, 2011
Messages
108
I'm trying to pass a variable from a modal form to the main form. In my main form, I'm using this command to open the modal form:

stDocName = "testselection"
DoCmd.OpenForm stDocName, , , , , acDialog, stLinkCriteria


After I've made my selections on my modal form, A variable is assigned the selections. I'm not closing the form, I'm setting me.visible = false.

With this being done, within the main form, I'm not able to recognize the variable created in the modal form.
 
If it's just a single value you wish to force into a control on your main form just use;
Code:
Forms!Mainform!ControlName = YourValueHere
You might find this page a useful reference.
 
It's not a control within the modal from. I'm having to create a variable based on multiple selections by the user.
 
I still see no reason you can't force it directly back into the control on your main form.
 
I'm needing to concatentate that variable into a query statement.
 
Instead of putting us on a "Drip Feed", why not simply outline exactly what it is you are trying to achieve in your OP :rolleyes:
 
I'm creating a form for the user with 4 selections. These 4 selections will create a variable used in a docmd.runsql make table statement. For the user. 3 of the selections are combo box fields. The 4th selection is named state, and it opens a modal form with all 50 states displayed as a check box selection. Within the modal form, I've created a variable that indicates which of the 50 states the user has selected. I'm needing to pass that variable back to the main form to add this to the make table statement. I've got everything working except passing that variable. I'm trying not to use a global variable. Thanks for all your assistance!!
 
OK, so why not pass that variable back to a non-visible text box on your main form and then use that in the same way you are using all the other controls on that form to build your SQL :confused:
 
Here what's I have so far:
within my modal form, this is what my variable looks like after selecting 3 states:
strcheckbox = (((ARCustomer.State) = "AZ")) or (((ARCustomer.State) = "MN")) or (((ARCustomer.State) = "TX"))

On the main form, this is my string for make table:
strqueryexport = "SELECT ARCustomer.Name, ARCustomer.City, ARCustomer.State INTO ExcelExport FROM ARCustomer WHERE "

strqueryexport = strqueryexport & strcheckbox

What do you think?
 
Here's a different idea.

If you make the modal form STORE the result in a global variable, when it closes your main form can get the value from there.

you can also then use the same modal form with other bits of your app if necessary.


it's easy to have mltiple values


eg - this declaration gives a "block" of two variables.

type tMdodalResult
region as long
customer as string
end type

public myModalResult as tmodalresult
 

Users who are viewing this thread

Back
Top Bottom