Global variables in VBA 
Author Message
 Global variables in VBA

Hi There,

Is it possible to declare a variable, assign a value to
that variable, and then have another form/query/object in
the project use that variable?
I have tried the Public declaration, but this appears to
only allow the variable access to other functions in that
form/query.  
Any ideas?

TIA

Phil Teale



Sat, 17 Sep 2005 07:29:47 GMT  
 Global variables in VBA
Put your Public declaration in a Module, not in the code associated with a
form.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele


Quote:
> Hi There,

> Is it possible to declare a variable, assign a value to
> that variable, and then have another form/query/object in
> the project use that variable?
> I have tried the Public declaration, but this appears to
> only allow the variable access to other functions in that
> form/query.
> Any ideas?

> TIA

> Phil Teale



Sat, 17 Sep 2005 07:39:14 GMT  
 Global variables in VBA
Thanks Doug,  I have put the declaration in a module, and
I can now use it in several forms, but what I'd like to be
able to do is give the variable a value in one form, then
use that value in another form.
This all forms part of a quick and dirty password module,
where the variable (NewPass) can be set in one form
(Maintenance), then used to password protect individual
forms by comparing the user's response to an InputBox  
with the value stored in NewPass.
Once again, any ideas would be greatly appreciated.
TIA
Phil Teale
Quote:
>-----Original Message-----
>Put your Public declaration in a Module, not in the code
associated with a
>form.

>--
>Doug Steele, Microsoft Access MVP
>http://I.Am/DougSteele



>> Hi There,

>> Is it possible to declare a variable, assign a value to
>> that variable, and then have another form/query/object
in
>> the project use that variable?
>> I have tried the Public declaration, but this appears to
>> only allow the variable access to other functions in
that
>> form/query.
>> Any ideas?

>> TIA

>> Phil Teale

>.



Sat, 17 Sep 2005 11:48:12 GMT  
 Global variables in VBA
On Tue, 1 Apr 2003 5:48:12 +0200, Phil Teale wrote

Quote:
> Once again, any ideas would be greatly appreciated.

Douglas gave you the answer, maybe it wasn't detailed
enough (or your OnlineHelp has disappeared ;-)):

Either:
-In a Code module:

   Public myVar As Long (or whatever)

-To get/set values, i.e. from a form's code module:

  <CodeModulName>.myVar = <your number/value>

Or:

-"hide" the public variable behind Property Lets/Gets:
  ModulCode:
  Private lngVar As Long (or whatever)

  Property Let MyVar(plng As Long)
     lngVar = plng
  End Property

  Property Get MyVar() As Long
     MyVar = lngVar
  End Property

-To set/get the variable (i.e. from From Code module):
  ModulLevelVariable = <ModulName>.MyVar
  <CodeModulName>.MyVar = 12
  etc.

(Or: create a class module that can hold all sorts of
 globals/passing info etc. ->you can find a lot about
 that if you search groups.google.com)

Michael



Sun, 18 Sep 2005 04:08:58 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Global variables in VBA

2. Global Variables / Global Objects

3. Referencing Global Variable from a variable

4. how to show a global variable in a report

5. Use multiple API calls or Global public variable?

6. Global Variable

7. VB Global Variable

8. global variables

9. Global Variable passed to Parameter

10. Set db as global variable?

11. Global Variables Lost 'on error'

12. using global variables in different forms

 

 
Powered by phpBB® Forum Software