I have a main menu form with 5 buttons. Each buttons defines my Location variable differently. This location will be then be displayed in a text box on several subsequent forms.
It works fine on one from, but not the other two. I put a MsgBox = Location in Form_Open to see what's going on. The variable is blank on the those two. It is not blank on the one that works. There is no obvious reasons for this. The general flow of the code of all the forms are the same. And no where do I reset the variable.
What's odd is that I changed the control source of the form that worked to no source (it doesn't need one; it is just a menu). Then the variable would be null when opening the form. OK. So it would seem that maybe your forms need to have a control source to access a global variable? No, because on one form that doesn't work it has a table control source and I can't change that anyway.
So, basically when does a Global variable lose it's value? Or a form can't see a global variable. All this code is in the same project.
Any help would be appreciated. Please don't tell me to use OpenArgs. I haven't got a good explanation of that yet and I would like to figure this out first. It should not be this difficult.
OK. So I changed Public Location to Private Location at the module level. The private method should make this variable available to everything in the same project with is all I need.
This time I got more info. The form that was working and could retrieve the variable still worked. Form2 said "invalid null" value for MsgBox Location. And Form3 said "variable not defined" for Location.
OK. One more thing. I put it back to Public Location. Form2 still gives an invalid use of null for MsgBox Location placed in Form_Open. But now Form3 just returns a blank Msg Box for the same MsgBox Location placed in Form_Open)
How can the exact same code placed at the beginning of Form_Open in two differents produce such differant results?
Thanks. The variable is still null when I open the form and it shouldn't be. It's not empty on the one form that is working right. Unless something happens before form_load or form_open, that I don't know about?
BTW. I created a new blank form and called the variable but it was still null. But when I set the form source to a table then it does work. WTF?.. NO Where does anything say anything about the form source affecting global variables. But then, it does not work on the other forms that do have a form source.
Forget about. I used the OpenArgs method and it works now. I see why people perfer that way. But I only wanted pretty simple Global variable.
And now I have like 50 dim statements throughout the project. I don't think I did that right.
How come it won't let me set my variables in the declarations section. Is that where your suppose to do it? I get errors if I put a dim statement there. So I had to declare them in each procedure.
That's fine with me if that's what everyone is talking about by writing more code. But if there is a more efficient way please let me know.
I renamed my location variable to Glocation. No problems as a Global variable now.
The error message I was getting were confusing and it wouldn't go into debug more. And I still don't see why if Location is a reserved name that it would work on one form, but not any other. (and there are no duplicate declarations for location). That would make you think there is a problem on those forms.