Public variables

jgc31

Registered User.
Local time
Today, 23:23
Joined
Dec 4, 2004
Messages
78
I have a question related to declaring variables in code related to forms. I want to share a variable between two sets of code on two seperate forms. I have made a declaration "Public GstrType As String" in the general declarations area of one of the forms but it does not seem to work, I get a variable not defined error when running the other form. I seem to remeber reading that there is an issue with this type of declaration but cant lay my hands on it. Any ideas? If I cant do it this way how can I do it?
 
Create a new standalone module and put your declaration there.

A form's module is a Class module and everything within it is enclosed and useable only - for the most part - by that form.
 
Thanks for the reply. Solved problem by using a hidden text field on one of the forms and returning the variable to there.
 
jgc31 said:
Thanks for the reply. Solved problem by using a hidden text field on one of the forms and returning the variable to there.

Why? What happened to the public variable?
 
I took a suggestion from Pat Hartman on a different thread that variables that needed to be shared between forms could be stored on a hidden form and adapted it slightly as the as the form were the variable is returned ( from a combo box) is always open at the same time as the form where the result is required ( one form "pops up" as a result of a certain action on the main form) . I had a thought lurking in the back of my mind that Access forms are individual modules and just needed to confirm this. So no more need for a public variable.
 

Users who are viewing this thread

Back
Top Bottom