Thread: [Solved] Global variables
View Single Post
 
Old 05-03-2019, 05:02 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by inlanoche View Post
It seems that sometimes the Global Var (public userRole as String) holds a value, and sometimes resets....
If I could better understand that, it may be usable for what I need.
Simply declaring a variable as public or global doesn't prevent it being reset. For example, with:
Public userRole as String
userRole can be cleared from any sub or function with code like:
userRole = ""
If you want to prevent userRole being reset use code like:
Const userRole As String = "Manager"

Note also that having:
Option Explicit
at the top of your code module will protect you from having something like:
Public userRole as String
but then referencing it as:
useRole
in your code - which quite understandably would come back as a null string.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote