here is the code i've used.. create a login screen with 2 text boxes (txtpass and txtname and an enter/login button on click event enter below. (of course have a users table to open.. work with it...
-- code for Click event of cmdEnter_Click()
Public Sub cmdEnter_Click()
Dim rst As dao.Recordset
Dim strSQL As String
'-- test username given, exit sub if not
If Nz(txtname) = "" Then
MsgBox "You must enter a name", vbInformation, "No Name Entered"
txtname.SetFocus
Exit Sub
End If
'-- test password given, exit sub if not
If Nz(txtPass) = "" Then
MsgBox "You must enter a password", vbInformation, "No Password Entered"
txtname.SetFocus
Exit Sub
End If
'-- create query to get record for specifed username
strSQL = "SELECT [FIRSTNAME], [LASTNAME], [SecretCode],[Security],[LOGINID] FROM [tUSERS] WHERE [LOGINID]='" & txtname & "';"
'-- run query
Set rst = CurrentDb.CreateQueryDef("", strSQL).OpenRecordset
'-- test if record found for given username, if not; incorrect username given
If Not rst.EOF Then
'-- test if password matches password in users record
If rst("SecretCode") = txtPass Then
DoCmd.OpenForm "frmMenu"
DoCmd.Close acForm, "frmLogin"
'-- correct password! now determine accesslevel, and open correct form
Else
'-- code to handle incorrect password
MsgBox "Password incorrect. Please try again...." & intLogonAttempts, vbExclamation, "Password orrect"
txtPass.SetFocus
End If
Else
'-- code to handle invalid username
MsgBox "Invalid UserName given. Please Try Again...." & intLogonAttempts, vbExcalamation, "Invalid UserName"
txtname.SetFocus
End If
'-- close up recordset object
rst.Close
Set rst = Nothing
'-- and finally, increment the logon attempt counter, quit access after 3 attempts!
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
'--Close Login Form