Public and Global Variables

slackpipe

New member
Local time
Today, 12:22
Joined
Feb 9, 2006
Messages
6
I am trying to write code that will generate some controls on a form based on information in a table. I've got that part of the code working. I have a main menu form that has a button that opens the form in design view, adds the controls and then opens it for use. My problem is, none of my public variables retain there value after the form is opened. I have tried using a global variable in a module and it doesn't work either. I added debug.print variables to the form_load. Then i added a button and copied the form_load debug.print statement to it's onclick event. It displays the correct values for the Form_Load, but 0, 0 for the onclick. does anyone know what would them to lose their values?
 
When you say that you put public variables in a "module" which module did you use? Did you stick them in the Declarations section of a regular module and not a form's module? I use that method all the time and I don't have a problem with them losing their values.

It sounds like you either put them in a form's module or into a sub or function within a regular module and not in the regular module's declaration section.
 
Public and global Variables

That's worked for me before too. But I've tried them in regular modules, i've tried havin them as variables in the form modules that copy from one form to another on open, and then onopen debug statements print the right values, but anytime the form tries to access them they return a value of 0. I've tried creating a class to store all the information together and having that set as a global variable in a standard module (worked onload, form can't access it), and i've tried having each from create an instance of the new class and added functions that allowed them to copy themselves, and that didn't work outside of the onload statement. For some reason the values are there for the debug statements in the onload event, but they are never accessible to my form. There is no other code in the form other then the debug.print statements in the onload and on an onclick event to check if the form can see them. I've passed variables a thousand times before. I can't figure out why this is giving me so many problems.
 

Users who are viewing this thread

Back
Top Bottom