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

Stuck on DLookup

Status
Not open for further replies.

ozzroo

Technical User
Feb 28, 2003
182
AU
I have a login form which users DLookup to get the password and username from a table called tblStaff

I also have a field in that table called "SecurityLevel"

If the users log in correctly this will go to the main menu

I want to be able to make buttons visible or not visible depending on user security level

I cant get my DLookup function to work on the main menu so it users the correct security level. I can get the currentuser to the main menu but not the security level.

My code is

If DLookup("[SecurityLevel]", "tblStaff", "[StaffID]=[Forms]![frmMainMenu]![CurrentUser]") <> "Administrator" Then
....

Any help please?
 
Try a small change:
[tt]If DLookup("[SecurityLevel]", "tblStaff", "[StaffID]='" &[Forms]![frmMainMenu]![CurrentUser] & "'") <> "Administrator" Then[/tt]
If StaffID is text or
[tt]If DLookup("[SecurityLevel]", "tblStaff", "[StaffID]=" & [Forms]![frmMainMenu]![CurrentUser]) <> "Administrator" Then[/tt]
If it is numeric.
 
The CurrentUser field on the mainmenu is sourced from the username combobox on the login form.

The code you gave me above doesnt come up with any errors. but whatever user I login with it always comes up with a true result even if the user is not an administrator. if they are a normal user it still works.

If DLookup("[SecurityLevel]", "tblStaff", "[StaffID]=" & [Forms]![frmMainMenu]![CurrentUSer]) <> "Administrator" Then
MsgBox "You are an Administrator"
Else
MsgBox "You are not an Administrator"
End If

I just used message boxes as a test. Like i said it comes up with "You are an Administrator" even if they are not.

Do I have to add statements for the other security levels?

The security level is not a text field, its a number field in the staff table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top