My database structure is very simple:
You open the logon form (Its the same structure used in
http://www.databasedev.co.uk/login.html), then you see a form called
"Entrada" and there you select a button to another form called "Req", and you
work there.
I have a table called "tblEmployees" its where i save users and passwords
(its the same structure used in
http://www.databasedev.co.uk/login.html).
I dont know if this help.
Okay, good start, but you've still got to store information on which users can open which objects. Access stores all
object names in MSysObjects, so you can use that if you like, but you've still got to store the "permissions"
I'd suggest a table like this:
tPermissions
---------------------------------
sObjectName Text, 255 chars (name of the Form, Report, etc)
sUserName Text, 50 chars (name of the user)
bCanOpen Yes/No field (True=User can open)
I'd add a Unique Index with sObjectName and sUserName as the fields, but that's not required.
Next, you'd need to populate that table. For example, let's say you have Users Sue, Sam, and Bob and you want to protect
the Forms frmAccounting, frmEmployees, and frmAdmin
tPermissions
---------------------------------
sObjectName sUserName bCanOpen
frmAccounting Sue T
frmAccounting Sam T
frmEmployees Sam F
frmEmployees Bob T
frmEmployees Sue F
frmAccounting Bob F
frmAdmin Bob F
frmAdmin Sue T
frmAdim Sam F
Next, after logging in the users, you'd then add code to check the permissions for each user as they move through the
database. Depending on how your db is strucutred, you might add this code in your Switchboard, or you might add it in
the Load or Open event of the Form. I'd opt for the Open event, as it can be cancelled:
'/in the code module for frmAccounting, for example
Private Sub Form_Open(Cancel As Integer)
Cancel = UserCanOpen(Me.Name, gUserName)
End Sub
This assumes that you have a variable named "gUserName" which is storing the name of the currently logged in user ... if
you don't then you'd need to change that to provide that username ... I haven't downloaded th sample from the link you
provided, so I don't know how it's being handled but I'll leave that to you.
Add this function to a Standard Module:
Function UserCanOpen(ObjectName As String, UserName As STring) As boolean
Dim rst As DAO.Recordset
Set rst = Currentdb.OpenRecordset("SELECT bCanOpen FROM tPermissions WHERE sObjectName='" & ObjectName & "' AND
sUserName='" & UserName & "')"
If Not (rst.EOF and rst.BOF) Then
UserCanOpen = rst("bCanOpen")
Else
'/if not record is found, allow the user to Open the object
'/Set this to False to disallow
UserCanOpen = True
End If
Set rst = Nothing
End Function
"Scott McDaniel" escreveu:
Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com