Creating a public or global variable

G

Guest

I have about 5 forms, each one conatining VB code. I want to create a
variable that can be passed along to each form (public or global) when the
forms have been opened or closed. How and where can I declare such a
variable? As Public, Private, Global, etc??

Thanks,
Matt
 
R

Rick Brandt

Matt said:
I have about 5 forms, each one conatining VB code. I want to create a
variable that can be passed along to each form (public or global)
when the forms have been opened or closed. How and where can I
declare such a variable? As Public, Private, Global, etc??

Thanks,
Matt

You can pass the value using the OpenArgs argument whenever you open a new form
or if you want to use a Public variable just declare it in a standard module
(not the module of a form or report).

Public MyVar as String
 
T

Tomas

It depends on the purpose of that variable. You can create a global variable
in any standard module (not form's class module) declaration section with

Public MyVariable as .... (this really means global variable)

and then refer to that variable from all those forms with just MyVariable.
But in this case all the forms will see any change of that variable and will
be able to change it.

The other way is to create 5 variables in each of the form's module
declaration section with the same

Public MyVariable as ...

and then refer to those variables with Forms("MyForm").MyVariable
 

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

Similar Threads


Top