VBA Code Improvement (1 Viewer)

Tupacmoche

Registered User.
Local time
Today, 05:56
Joined
Apr 28, 2008
Messages
291
I have code used to give access to a button in my application. What, I want to do is improve it and make it more flexible to update. Specifically, a new users is needed but since I coded it (see below), I have to wait until the end of the day to make the change. Is there a table based method that, I can use and simple add a new user? :)



Code:
 Public Function DecUser()
Dim UserC As Boolean
UserC = False

If GetCurrUser = "Robert Slim" Or _
   GetCurrUser = "Elizabeth Wright" Or _
   GetCurrUser = "Andrew Small" Or _
   GetCurrUser = "Travis Dell" Or _
   GetCurrUser = "Erica Harris" Or _
   GetCurrUser = "Mitzie Zee" Or _
   GetCurrUser = "Chris Meeby" Then UserC = True
If UserC = False Then
Else
End If
DecUser = UserC
End Function
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:56
Joined
Sep 21, 2011
Messages
14,319
Use a Dlookup for the currentuser and see if the buttonAllowed is true ?
 

Tupacmoche

Registered User.
Local time
Today, 05:56
Joined
Apr 28, 2008
Messages
291
I have used currentuser() and it evaluates correctly but, I need a table based implementation.
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:56
Joined
Sep 21, 2011
Messages
14,319
I have used currentuser() and it evaluates correctly but, I need a table based implementation.

So put the userids in a table

tblAccessRight
AccessRightID
AccessRightUser
AccessLevel

Look for that user and see what their AccessLevel is. If the correct value, show the button, whatever.
 

plog

Banishment Pending
Local time
Today, 04:56
Joined
May 11, 2011
Messages
11,648
Here's what you do:

Create a table (tblValidUsers) with a field called UserName
Populate it with all the values you have in that If expression
Replace your logic in your code with this stub:

Code:
If (DCount("[UserName]", "tblValidUsers", "UserName='" & GetCurrUser & "'")>0) Then
  Is A valid user
Else 
  Is not a valid user
 

Users who are viewing this thread

Top Bottom