Rob,
This is not real secure. Here is one way to do it. You will need a way to determine who the use is. You could use a log in screen and capture user's initials and PW and compare against the table entry, then set a Global variable for who the user is and what their permission level is. In the on_Load for your forms, check the user's permission level (Global)and set either the visible or enabled property for the control based on the Global permission level variable.
*********************************************
in a button on the User Log in Screen:
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim strUserPasswordInput As String ' hold password user gives to compare, Dim varFoundUserPW As Variant ' store user's PW
Dim strUserInitInput As String ' store user initials,
Dim strUserPWStored As String
Dim strUserInitStored As String
Dim intUserLevelStored As Integer
Set db = CurrentDb
Set rec = db.OpenRecordset("tblauthusers", dbOpenDynaset) ' updated 6-29-05
' make sure user performed!
txtUserInit.SetFocus
If txtUserInit.Text <> "" Then
strUserInitInput = txtUserInit.Text
Else
MsgBox "You must enter valid user initials and password"
Me.txtUserInit.SetFocus
rec.Close
Exit Sub
End If
txtUserPassword.SetFocus
If txtUserPassword <> "" Then
strUserPasswordInput = txtUserPassword
Else
MsgBox "You must enter valid user initials and Password"
Me.txtUserInit.SetFocus
rec.Close
Exit Sub
End If
rec.FindFirst "[AuthInit] = """ & strUserInitInput & """"
If rec.NoMatch Then
MsgBox "You have entered invalid User Initials or password."
Else ' user initials match
strUserInitStored = rec("AuthInit")
strUserPWStored = rec("Password")
intUserLevelStored = rec("level")
End If
If strUserPWStored = strUserPasswordInput Then
strUserInit = strUserInitStored ' set global
intAuthLevel = intUserLevelStored ' set global, objects become visible depending on setting
DoCmd.OpenForm "frmmainmenu"
DoCmd.Close acForm, "frmUserID", acSaveNo
Else
MsgBox "You must enter valid user initials and PASSWORD"
Exit Sub
End If
rec.Close
Set rec = Nothing
End Sub
*******
The tblAuthUsers contains:
AuthID (PK)
AuthInit (Users Initials for Log in)
AuthName (users name)
Level (a long representing level of permission)
Password (text containing the PW)
************
an example of how to code a form's on_load event to allow a user with a specific level to see the button cmdOpenUpdateForm:
If intAuthLevel = 1 Then
cmdOpenUpdateForm.Visible = True
Else
cmdOpenUpdateForm.Visible = False
End If
*********
Create your Global variables in a module. You may want to call the module "Globals"
*******************************************
You may want to create a button or two for yourself to use during development that will re-set the permission level (such as if Level 6 is your highest level and allows you to do everything, code the button to reset the global variable to the value 6. WHEN something goes wrong during testing and your project gets reset after responding to a debug, you will loose your variable. Of course, before delivery, remove the button or set it to invisible.
HTH,
Loralee
|