hi Im new to access, i have created a login form with the following code.
Option Compare Database
Option Explicit
Private Sub btnLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tbl1Employees", 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 <> Nz(Me.txtPassword, "") Then
Me.lblWrongPass.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
Me.lblWrongPass.Visible = False
DoCmd.OpenForm "UserInterface"
DoCmd.Close acForm, "frmLogin"
End Sub
I have a table called tbl1Employees with the following fields, Employee ID (primaryKey) Username, Password
The form has text box username and text box password. There are two invisible labels incorrect usernameand incorrect password and then a login button. Event procedure (on click) of login button is the above code but i just cannot get it to work any help appreciated in sorting this out
Option Compare Database
Option Explicit
Private Sub btnLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tbl1Employees", 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 <> Nz(Me.txtPassword, "") Then
Me.lblWrongPass.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
Me.lblWrongPass.Visible = False
DoCmd.OpenForm "UserInterface"
DoCmd.Close acForm, "frmLogin"
End Sub
I have a table called tbl1Employees with the following fields, Employee ID (primaryKey) Username, Password
The form has text box username and text box password. There are two invisible labels incorrect usernameand incorrect password and then a login button. Event procedure (on click) of login button is the above code but i just cannot get it to work any help appreciated in sorting this out