Navigation form: limit access to tabs (Help)

cstickman

Registered User.
Local time
Today, 02:33
Joined
Nov 10, 2014
Messages
109
Hello Fellow Access Users

So I created a new navigation form and want to limit which tabs are enabled based on security level. So I have a table called tbluser and it has the following fields
userlogin
username
security - Admin or User

What I would like to happen is if they are an admin have 5 extra navigation buttons be available. If they are just a user have the same 5 disabled and if they are not in the list at all then to close the program. Here is what I wrote and I am getting an error "run-time error'2471':
The expression you entered as a query parameter produced this error: '[UserLogin]'

The UserLogin is the username of the computer since we are in a networked environment. The username is actually stored in the tbluser as userlogin. I am not sure if this is playing a part of the problem or not.

<code>
Private Sub Form_Load()
Dim UserLogin As String
Dim userLevel As String

UserLogin = Environ("Username")
Me.user = UserLogin
If IsNull(DLookup("[security]", "tbluser", "[UserLogin] = '" & Me.user & "'")) Then
Else
userLevel = DLookup("[security]", "tbluser", "[UserLogin] = '" & Me.user & "'")
If userLevel = Admin Then
Me.NavigationButton13.Enabled = True
Me.NavigationButton17.Enabled = True
Me.NavigationButton15.Enabled = True
Me.NavigationButton27.Enabled = True
If userLevel = user Then
Me.NavigationButton13.Enabled = False
Me.NavigationButton15.Enabled = False
Me.NavigationButton17.Enabled = False
Me.NavigationButton27.Enabled = False
Else
DoCmd.Quit acQuitSaveAll
End If
End If
End If

End Sub
</code>
 
Last edited:
Set a breakpoint on your first statement then load the form and advance one line at a time (F8) and find out which line is having the problem.
 
Private Sub Form_Load()
Dim UserLogin As String
Dim userLevel As String

UserLogin = Environ("Username")
Me.user = UserLogin
userLevel = DLookup("[security]", "tbluser", "[UserLogin] = '" & Me.user & "'") & ""
If userLevel = "" Then
DoCmd.Quit acQuitSaveAll
Else
If userLevel = "Admin" Then
Me.NavigationButton13.Enabled = True
Me.NavigationButton17.Enabled = True
Me.NavigationButton15.Enabled = True
Me.NavigationButton27.Enabled = True
ElseIf userLevel = "user" Then
Me.NavigationButton13.Enabled = False
Me.NavigationButton15.Enabled = False
Me.NavigationButton17.Enabled = False
Me.NavigationButton27.Enabled = False
End If
End If
End Sub
 
James - thank you for the suggestion and I did discover I was referencing a wrong column.

Arnelgp - Thank you very much!! The new code works like a charm!!
 

Users who are viewing this thread

Back
Top Bottom