Login Form with access rights

VTG

New member
Local time
Today, 08:17
Joined
Apr 4, 2008
Messages
6
hi, i have two forms, Form A to login and enter Form B (provided that the logging in credentials are correct)
Form A has two fields (txtUserName and txtPassword)
what i want to do is, how do i 'filter' out the users that do not have sufficient access rights? (i.e. Advanced)
could i use the Dlookup function to look up in the table 'tblEmployee' for the field 'AccessRights', if so, how would i code it?

this is currently my code for the button in Form A that goes to Form B if the logging in credentials are correct:

Private Sub cmdGo_Click()
'Check to see if data is entered into the UserName combo box

Dim EmployeeID As Long

If IsNull(Me.txtUserName) Or Me.txtUserName = " " Then
MsgBox "Please enter your Username", vbOKOnly, "Required Username"
Me.txtUserName.SetFocus
Exit Sub
End If
If IsNull(Me.txtPassword) Or Me.txtPassword = " " Then
MsgBox "Please enter your password", vbOKOnly, "RequiredPassword"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this matches value chosen in combo box

If Me.txtPassword = DLookup("Password", "tblEmployee", "[EmployeeID]=" & Me.txtUserName) Then
EmployeeID = Me.txtUserName.Value

'Suggested code (i know it's wrong)
Exit Sub
End If
If EmployeeID = Dlookup("AccessRights","tblEmployee","[AccessRights]" = Advanced)

DoCmd.Close
DoCmd.OpenForm "Form B", acNormal
Else
MsgBox "Sorry, the username or password that you have entered is not correct, please try again", vbOKOnly, "Username/Password not correct"
Me.txtPassword.SetFocus
Exit Sub
End If
End Sub

help would be much appreciated and thanked
 
The second Dlookup would look like the first, except for the field to be looked up (and once you have 2 fields to lookup, it would be more efficient to open a recordset).
 

Users who are viewing this thread

Back
Top Bottom