Pass variable from one form to another?

G

Guest

I am trying to pass the value of a variable from one form
to another.
I defined it as

Public myvariable as string

in 1st form and then in the 2nd form
I try to use this value - myvariable, it doesn't show anything.

Is this the right way to do it?

Thank you,
-Me
 
D

Douglas J. Steele

If you've declared the public variable in code associated with a form, you
need to refer to that form in order to refer to the variable. Assuming the
1st form is name Form1, you can use:

Forms_Form1.myvariable

or

Forms("Form1").myvariable

If you're opening the 2nd form from the 1st form, you can pass a value using
the OpenArgs property.
 
G

Guest

Create a blank module.
Enter your definition there:

Public myvariable as string

Close and save the module.
Now the variable can be accessed by all forms, queries, reports, etc.

jmonty
 
G

Guest

You can create a module. In the module place the statement
Public myvariable As String

Save the module and give it a name. If you use the default name, Module1,
then
in form1 before you open form2 place the statement

Module1.myvariable = "Your variable goes here"

Now in form2 you can reference Module1.myvariable as in

Me.Text0 = Module1.myvariable

HTH
 

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