Link to home
Start Free TrialLog in
Avatar of Sandra Smith
Sandra SmithFlag for United States of America

asked on

Difference between a Global variable and Public in declaration section of module

Is there a difference if a variable is dimentioned as:
Global gstrUserID   vs  strUserID
when declared at the top of a module (not a form or report module)?  I want the variable to be used throughout the application.

Sandra
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Sandra,

 Nothing really.  It's just that with a module level variable, you do have the option of using the Public or Private keyword with it, so you can restrict it's scope to the module.

With a global, it's always public.

Jim.
Avatar of Sandra Smith

ASKER

Jim, I think I am getting confused then on how to use it.  I want the variable to be available to all procedures throughtout - that is, all modules in the database, forms, reports, etc..  What I want to happen is when the user opens the database, the opening form grabs the user's ID and sets this variable to its value.  At that point, I am hoping this value (gstrUserID) is now available throughout the database and for whatever processes or procedures, forms, reports that the user selects.  The userid is teh basis for granting or restricting access to various forms/reports.  Or, when the main menu is closed and another form is opened, does the value of this global variable go out of scope?  It seems I am losing this value and am not sure why.

Sandra
Avatar of Norie
Norie

Sandra

Why can't you 'grab' the ID each time you need it?
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I do not want to just "grab" it as it is used so often, it simply would make repeated calls to the VBUserName procedure.  It is much tidier this way.  However, I do like the idea of a hidden form and it seems to work.

Sandra
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial