Option Explicit
Public LoginSucceeded As Boolean
-----------------------------------------------------
Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Me.Hide
End Sub
---------------------------------------------------------
Private Sub cmdOK_Click()
'check for any record, if there is no record there could be error when looping
If Data1.Recordset.RecordCount = 0 Then
MsgBox ("No recordset")
Exit Sub
End If
'check for correct username and password
Data1.Recordset.MoveFirst
Do While Not Data1.Recordset.EOF
If txtUserName = Data1.Recordset.Fields("Username") Then
If txtPassword = Data1.Recordset.Fields("Password") Then
LoginSucceeded = True
Me.Hide
Form1.Show
End If
End If
Data1.Recordset.MoveNext
Loop
If Not LoginSucceeded Then
MsgBox "Invalid UserName/Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
_________________
