I have a "Users" table that keeps up with Usernames, Passwords, and Security Levels. Then I have a User Login form that is set to load on open.
When they click "OK" to log in this code runs:
Code:
Private Sub btnOK_Click()
On Error GoTo help
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Select * from Users where username = '" & txtUserName.Value & "' AND password = '" & txtPassword.Value & "'")
If rs.RecordCount = 0 Then
'No user - authentication failed
MsgBox "Invalid username or password! Please try again.", vbCritical, "Login Error ..."
Exit Sub
Else
Level = rs.Fields("Level")
DoCmd.Close
DoCmd.OpenForm "frmMainMenu", acNormal
End If
Exit Sub
help:
If Err.Number <> 0 Then
MsgBox Err.Description
End If
End Sub
Then you can go to "MainMenu" Form_Load() and do something like this:
Code:
Private Sub Form_Load()
'Setup permission load
'1 = View/Edit User
'2 = Admin User
btnLogOut.SetFocus
Main.Visible = False
People.Visible = False
'View Edit User
If Level = 1 Then
'Main.Visible = True
'People.Visible = False
End If
'Admin User
If Level = 2 Then
'admin user
Main.Visible = True
People.Visible = True
End If
End Sub
Declare "Level" as a Public Variable (Interger)
This will keep them logged in until they close the database or click "Log-out". Every time someone opens it they have to log-in. Not sure if that's what you were talking about.