I want to set the user login access in MS Access which means that if the user logs in as the admin it will show a different form.
I have tried to get the userlevel
which is a string and will show things like "Admin"
or "User"
but it indicated:
Invalid use of Null
At this line:
UserLevel = DLookup("UserSecurity", "tblUser", "[UserLogin] = ' " & Me.txtLoginID.Value & "'")
Here is the full code:
Private Sub Command1_Click()
Dim UserLevel As String 'get the dlookup value
Dim TempPass As String
If IsNull(Me.txtLoginID) Then
MsgBox "Please Enter Login ID", vbInformation, "Login Id Required"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtLoginPass) Then
MsgBox "Please Enter Password", vbInformation, "Login password Required"
Me.txtLoginPass.SetFocus
Else
'process the job
If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'"))) Or _
(IsNull(DLookup("password", "tblUser", "Password = '" & Me.txtLoginPass.Value & "'"))) Then
MsgBox "Incorrect Password"
Else
TempPass = DLookup("password", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "'")
UserLevel = DLookup("UserSecurity", "tblUser", "[UserLogin] = ' " & Me.txtLoginID.Value & "'")
'get the usersecurity whcih indicate he is admin or user
DoCmd.Close
If UserLevel = "Admin" Then 'if admin then open employee form else open customer form
'MsgBox "Login ID and password correct "
DoCmd.OpenForm "Employee"
Else
DoCmd.OpenForm "CustomerForm"
End If
End If
End If
End Sub
I have tried to use Nz()
but it gives me a null value which takes me to the customer form.