Hey Guys how’s everyone been
Need some guidance, please. I have this login form with three assigned users each have their own password. I want to have a feature where someone logs in and a message box pops up saying Welcome with the First Name of whoever is logged in. It does want I want but it keeps displaying only the first user name to primary key ID:1 and for the other users also. What am I evaluating wrong here, Any suggestions please?.
This is my code below am trying to figure out my error, should I create a private function of UserName text box i.e. txtUserName?
Code:
Private Sub btnLogin_Click()
Dim rs As Recordset
Dim userx As String, user As String
userx = "WELCOME"
user = DLookup("FirstName", "tblUsers", Me.txtUserName)
Set rs = CurrentDb.OpenRecordset("tblUsers", 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 = True Then
Me.lblWrongPass.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
If IsNull(Me.txtPassword) Then
MsgBox "Please Enter Valid Password!", vbInformation, "Database Management System"
Me.lblWrongPass.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
If rs!Password = Me.txtPassword = True Then
Me.lblWrongPass.Visible = False
Me.lblWrongUser.Visible = False
DoCmd.OpenForm "frmMAIN"
MsgBox userx & ", " & user, , " Database Management System"
DoCmd.Close acForm, Me.Name
End If
End Sub