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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a Global Variable

Status
Not open for further replies.

bostonfrog

Programmer
Jul 14, 2003
79
MX
In a module I declared a public variable called gUserName As String, available to be used on any form or object in the database. It's current value is stored depending on who logs on from a logon form. For example, I am using the value of gUserName to determine what happens when a form loads, but I've hard-coded the users' names (2 letters), and it won't be useful if new users are added later and there is no one to edit the VB code! This is how it looks now, but this code isn't any good in the long term:

Code:
Private Sub Form_Load()
  Select Case gUserName
    Case "ka", "kb", "de", "mb", "dm", "rp"
      ' change recordsource dynamically
      ' change form's caption
      ' do other things to the form ...
    Case "ms", "mm", "es", "sp", "cm", "mg"
      ' change the recordsource
      ' change the form's caption
      ' do other things to the form ...
  End Select
In this case, there would always be these 2 sets of users (some who are downtown and others uptown), and thus two cases continually re-used. Any suggestions?
-- Michel
 
Of course it's hard to tell exactly what's going on with this code but it seems as though you need a table of users with a certain profile associated with them. When the profile i 'uptown'(or other) then one case will execute. IF it were 'downtown' then a different case would execute. These would have to be maintained in the user profile table. When UserName is loaded then aslo load UserProfile or UserPrivilidge or something like that. Then you caan use the case to determine their privilidged actions.
 
Every database I put together, I setup security for it. Consequently, I would use security to deal with the problem. I would set up 2 groups. And then assign users to the groups. Then I would determine which group the user is a member of. For example:

If (MemberOfGroup("Group1",CurrentUser)) then
do this and that
else
do this
end if

If you want to go this route, I can give you directions on how to set up security (pretty easy, once you know what to do) and include a copy of the function MemberOfGroup.
 
Thanks for that advice! I got me thinking that I should create a different variable called gUserLocation, rather than employing the users' initials. This way, there would be a [location] field in the table, and the Case would use the the location instead of the user name.
- Michel
 
Thanks, FancyPraire. This unfortunately is not a secured database for now, so I am using an insecure log-in. It's being used temporarily. In the past I tried setting up Access security but had too many problems with it -- My .mdw was totally messing things up and was not able to log into any newly-created Access database normally again. I read some of the online info about Access security but it was still causing every instance of Access to default to my newly-created .MDW, even if I opened my database with a command line in a shortcut using the /MDW_Name parameter. Any advice would be most appreciated. I find Access security very tricky to implement. I was so afraid of making Access unusable for others, that I stopped using the security feature and re-joined the default .MDW with the workgroup admin. program. I still wanted the ability to allow others on the computer to create unsecured databases, but Access was creating all new databases using my own .MDW.
Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top