I don't know what I am doing wrong when I login as user Y= 3 then it gives me error 2467. "the expression you entered refers to an object that is closed or does not exist."
and take me to the code line highlighted below.
I think it's confusing Y for 1, 2 and 3 as if I comment 1 and 2 code then 3 works fine and vice versa.
Code:
Private Sub Command10_Click()
If IsNull(txtUsername) Then
MsgBox "Invalid Username"
Exit Sub
End If
If IsNull(txtPassword) Then
MsgBox "Invalid Password"
Exit Sub
End If
Dim X As Long
X = Nz(DLookup("UserID", "UserT", "Username='" & txtUsername & "' AND Password='" & txtPassword & "'"))
If X > 0 Then
Dim Y As Long
Y = Nz(DLookup("GroupID", "GroupXUserT", "UserID='" & X & "'"))
'MsgBox "" & Y & ""
'We have a valid user
If Y = 1 Or 2 Then
DoCmd.OpenForm "MainMenu"
Forms!MainMenu!txtUserID = X
LogIt X, "User Logon"
Forms!MainMenu!txtUsername = txtUsername
DoCmd.Close acForm, "LoginF"
End If
Else
MsgBox "Invalid Logon"
End If
If Y = 3 Then
DoCmd.OpenForm "MainMenu"
Forms!MainMenu!txtUserID = X
LogIt X, "User Logon"
Forms!MainMenu!txtUsername = txtUsername
DoCmd.Close acForm, "LoginF"
Forms!MainMenu!Command27.Visible = False
End If