Define Global Variable?

G

Guest

I have a need to use a field value from one
form to another. I think I should define a global
variable?

How can I define a global variable or how
can I achieve this?

Thank you,
-Me
 
M

Marshall Barton

Me said:
I have a need to use a field value from one
form to another. I think I should define a global
variable?

How can I define a global variable or how
can I achieve this?


A "global" (actually the word is Public) variable is
declared in the declarations section of a standard module.

Public somevariable As whatevertype

But, if both forms are open when you want to do this,
there's no need for a global variable. The value of the
"field" in the first form can just be used in the second
form by referring to it:
Forms!firstform.controlname
 
G

Guest

Hi Marshall,

Thanks for the reply!

Now when I use Forms.firstform.<myfieldnamefrom1stform>

I get error - "MS can't find the firstform ..."

What I maybe doing wrong.

I am calling the 2nd form using command button.

2ndly,I was using public <myvariable>, when
I referred to it in the 2nd form it would be null,
however, even before calling the 2nd form, it would
display the value in <myvariable> correct.

Any ideas?

Thank you,
-Me
 
M

Marshall Barton

Me said:
Now when I use Forms.firstform.<myfieldnamefrom1stform>

I get error - "MS can't find the firstform ..."

What I maybe doing wrong.

I am calling the 2nd form using command button.

2ndly,I was using public <myvariable>, when
I referred to it in the 2nd form it would be null,
however, even before calling the 2nd form, it would
display the value in <myvariable> correct.


Can we get away from the name guessing game and use the real
names that's you actually have in your app?

Trying to follow your lead above, that reference would be:

Forms!<firstform>.<myfieldnamefrom1stform>

You had changed the ! to a . so there's no wonder it got an
error.

You didn't provide enough info for me to determine why you
see a Null in the second form. A common reason is that the
variable was reset because you ran into an unhandled error
somewhere. Another is that you declared the variable in a
form module instead of a standard module or you may have a
duplicate declaration in the second form's module.
 

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