I want to set the user login access in MS Access which means if user enters as the admin it will show diffrent 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 & "'")

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 take me to customer form.

0 Answers