Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to declare global variables?

Status
Not open for further replies.

Doraemon

IS-IT--Management
Sep 12, 2003
31
HK
First of all, thanks for your help in advance.

I am a new user of VBA in Access, so I am not sure how to declare global variables in VBA in Access.

More specifically, I have created many "private Sub_xxx" for all forms in Access. But I would like those forms to be able to fetch and change a common variable (so I need a global variable).

I have tried to declare as:
Static variable_name As Integer
But, it does not work.

I have also tried to declare a variable in a module, say Module_1. But it also does not work.

Sorry that my question is a bit long, but can you please tell me specifically how to declare a global variable which can be shared among all "private Sub form0x"?

Thanks a lot!
 
In your module, i.e. Module_1, up at the top, right below the "Option" statements, declare your variable(s) in the following format:

Public varname As type

For example:

Public strMyString As String
Public intMyNumber As Integer
Public OnOff As Boolean
Public frmMyForm As Form

HTH...

Ken S.
 
Hmmmm, maybe try declaring as Public...

Public variable_name As Integer



[yinyang]
 
Great! My variable can work now. Really thanks u two for your help.

Recently, I have tried a lot of times, but still can succeed, maybe I have placed the variable in the wrong place. Now, it works fine!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top