Hello, Ive been trying to create a form where if the user inserts a username and password, the form will log in and send the user to another form. I searched around the internet for a while and I found a code that allowed me to this, but I do not understand it so can someone please explain it to me?
Also how can I make it so that when the user opens the database the log in form popsup and does not let the user access any other part of the database until he/she has logged in?
The Code:
Private Sub cmdLogin_Click()
On Error GoTo Err_cmdLogin_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim recSet As Recordset
Dim isOK As Boolean
Dim txUsername As String
Dim txPassword As String
Set recSet = CurrentDb.OpenRecordset("Login Credentials", dbOpenTable)
txtusername.SetFocus
txUsername = txtusername.Text
txtpassword.SetFocus
txPassword = txtpassword.Text
With recSet
Do While Not .EOF
If txUsername = !UserName And txPassword = !Password Then isOK = True
.MoveNext
Loop
End With
If isOK = False Then MsgBox ("Invalid username/password!")
If isOK = True Then
stDocName = "Main"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
recSet.Close
Exit_cmdLogin_Click:
Exit Sub
Err_cmdLogin_Click:
MsgBox Err.Description
Resume Exit_cmdLogin_Click
End Sub