Hello,
I have a code in access to open certain forms depending on the security level of the user.
However, I have been getting a run time error code 13 type mismatch. What am I doing wrong?
This is the section where the error pops up:
And this is the full code:
I have a code in access to open certain forms depending on the security level of the user.
However, I have been getting a run time error code 13 type mismatch. What am I doing wrong?
This is the section where the error pops up:
Code:
SecurityLevel = DLookup("SecurityLevel", "Employees", "UserName='" & Me.txtusername.Value & "'")
And this is the full code:
Code:
Option Compare Database
Option Explicit
Private Sub btnlogin_Click()
Dim SecurityLevel As Integer
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("employees", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.txtusername & "'"
If rs.NoMatch = True Then
Me.lblwronguser.Visible = True
Me.txtusername.SetFocus
Exit Sub
End If
Me.lblwronguser.Visible = False
If rs!Password <> Me.txtpassword Then
Me.lblwrongpassword.Visible = True
Me.txtpassword.SetFocus
Exit Sub
End If
Me.lblwrongpassword.Visible = False
SecurityLevel = DLookup("SecurityLevel", "Employees", "UserName='" & Me.txtusername.Value & "'")
DoCmd.Close acForm, Me.Name
If SecurityLevel = 1 Then
DoCmd.OpenForm "Admin Form"
Else
DoCmd.OpenForm "Management Form"
End If
If SecurityLevel = 2 Then
DoCmd.OpenForm "Management Form"
Else
DoCmd.OpenForm "User Form"
End If
End Sub