Hello, I am trying to have a user login with a Username and Password in order to access the frmMain.
I have the following code:
Option Compare Database
Option Explicit
Private Sub btnLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tblUser", 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
DoCmd.OpenForm "frmMain"
DoCmd.Close acForm, Me.Name
End Sub
Yet I enter the username and password I receive:
Compile error:
Invalid outside procedure
What am I doing wrong?
Thank you
I have the following code:
Option Compare Database
Option Explicit
Private Sub btnLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tblUser", 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
DoCmd.OpenForm "frmMain"
DoCmd.Close acForm, Me.Name
End Sub
Yet I enter the username and password I receive:
Compile error:
Invalid outside procedure
What am I doing wrong?
Thank you