Setting a Global Variable

collizz

Registered User.
Local time
Today, 16:04
Joined
Feb 6, 2006
Messages
29
Hi

I need to create a global variable (user access level) in my Access 2007 application, that can be accessed throughout the application. I believe this involves putting together a Standard Module and defining the variable within a Sub procedure?

Code for my module follows:

*************************
Option Compare Database
Option Explicit

' Standard Module

Sub SetGlobalVars()

Dim gblAccessLevel As String
gblAccessLevel = "XXX"

End Sub
*************************

The module runs in debug with no errors, but the variable is not recognised outside of the Standard Module.

My question is: How do I execute the module's code when the application starts up (in my case, a Login form) to set this instance variable?

Thank you.
 
in your startup module you need to declare the global variable. The best method is

Public MyVariableName As String

Older versions of Access used

Global MyVariableName As String

but both work.
 

Users who are viewing this thread

Back
Top Bottom