Hey everyone,
I am getting a compile Error "Else without If" when I run my login screen. I am stumped as to why. I dont know were I would be missing an "If". I believe it is throwing the error on the very last Else statment that I have. What is supposed to happen is the very first If statment runs. if the user name and or password are blank then it skips all the missile and goes to the last else statement. Could you please just look over it it and make sure I have it correct.
Thank you.
Here is the code:
Code:
Option Compare Database
Option Explicit
Private Sub btnLogin_Click()
Dim rs As Recordset
Me.lblWrongUN.Visible = False
Me.lblWrongPas.Visible = False
If Not IsNull(Me.TxtUserName) And Not IsNull(Me.TxtPassword) Then
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblUserPass WHERE UserName='" & Me.TxtUserName & "'", dbOpenSnapshot, dbReadOnly)
If rs.EOF Then
Me.lblWrongUN.Visible = True
Me.TxtUserName.SetFocus
Else
If rs!Password <> PE(Me.TxtPassword) Then
Me.lblWrongPas.Visible = True
Me.TxtPassword.SetFocus
Else
DoCmd.OpenForm "AllTrackMainPage"
DoCmd.Close acForm, Me.Name
End If
TempVars("UserType") = rs!UserType_ID.Value
If rs!UserType_ID = 1 Then
Dim prop As Property
On Error GoTo SetProperty
Set prop = CurrentDb.CreateProperty("AllowByPassKey", dbBoolean, False)
End If
CurrentDb.Properties.Append prop
SetProperty:
If MsgBox("Would you like to turn on the bypass Key?", vbYesNo, "Allow Bypass") = vbYes Then
CurrentDb.Properties("AllowBypassKey") = True
Else
CurrentDb.Properties("AllowBypassKey") = False
End If
Else
MsgBox "Must enter " & IIf(IsNull(Me.TxtUserName), "Username", "Password")
End If
End Sub