Hi all.
For my own reasons I want a variable (holding a persons name) to be available in all forms. So I need to declare a global variable. Fine. I have read in these forums and on other websites but only get an overview, so some queries remain.
In my project I create a new module. Naming the module shouldn't matter other than it makes sense. I assume there is no list of pre allocated titles as there are with keywords? Is there a default 'Global' module I should create and use?
My module looks like this at the moment, full of scraps...
module name is GlobalStuff.
Code:
Option Compare Database
'Declare the variables themselves
Public gblCurrentUser As String
Public gblUserID As String
Dim strUser As String
Option Explicit
'This was copied over from a web page example. Junk at the moment.
Private Sub Form_Open(Cancel As Integer)
' doing something here
End Sub
'This is for the db to get this info at the beginning. It will be (isn't yet) called from the form_open event of the first form.
Public Sub subGetWindowsUsername()
strUser = Environ("USERNAME")
End Sub
http://www.blueclaw-db.com/access_da...l_variable.htm
This page has this code...
Code:
The following is the code we use to initialize our VBA global variables:
Option Compare Database
'Access global variables definition
Global GBL_Username As String
Global GBL_Previous_Tab As String
Option Explicit
Questions are... what does the 'global' word do? When I F1 over it I get help refering to "Public Statement". Is it, in this module, better than using Dim?
I have seen remarks saying Global variables are potential problems, but not telling why they are. What should I look out for?
I know this stuff is buried in the books but I am digging out the stuff I need to know as I go. Probably the worst way to learn.
That's enough. Happy Christmas to you all and thanks in advance for any light you can shed on my understanding.
Mike.