So, I've been putzing around with this code for a few days now for a login form. Everything seems to be working correctly except I cant get passed the strSQL. It pops up a "Run-time error '3061': Too few parameters. Expected 2." I'm using a thread from the following link.
wwwDOTdatanumen.com/blogs/how-to-protect-your-sensitive-data-with-a-login-form-in-access/
Any help would be appreciated. Please and thank you!
wwwDOTdatanumen.com/blogs/how-to-protect-your-sensitive-data-with-a-login-form-in-access/
Any help would be appreciated. Please and thank you!
Private Sub cmd_login_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
If Trim(Me.txt_UserName.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Username should not be left blank.", buttons:=vbInformation, title:="Username Required"
Me.txt_UserName.SetFocus
Exit Sub
End If
If Trim(Me.txt_Password.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Password should not be left blank.", buttons:=vbInformation, title:="Password Required"
Me.txt_Password.SetFocus
Exit Sub
End If
'query to check if login details are correct
strSQL = "SELECT FirstName FROM tbl_login WHERE Username = """ & Me.txt_UserName.Value & """ AND Password = """ & Me.txt_Password.Value & """"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
If rst.EOF Then
MsgBox prompt:="Incorrect username/password. Try again.", buttons:=vbCritical, title:="Login Error"
Me.txt_UserName.SetFocus
Else
MsgBox prompt:="Hello, " & rst.Fields(0).Value & ".", buttons:=vbOKOnly, title:="Login Successful"
DoCmd.Close acForm, "frm_login", acSaveYes
End If
Set db = Nothing
Set rst = Nothing
End Sub