Setting User Permissions In Forms

  • Thread starter Thread starter bzeyger
  • Start date Start date
B

bzeyger

Hello,

I am a new Access VBA User and I have created a Project Managment DB. It
consists of many forms, Queries, and Forms. I have created 4 different levels
of users. How do I change the permission rights to each form. One form might
allow Adims to chage data, while the same form could have read only rights
for regualr users.

Is there an easy way to chage the basic Access permissions for the forms?
 
I usually use the forms Load event to set various form properties
(AllowEdits, AllowAdditions, AllowDeletions) and to lock or hide specific
controls base on user roles. Something like:

Private Sub Form_Load()

Dim bAdmin as boolean, bPower as boolean, bUser as boolean
Dim strCriteria as string
Dim ctrl as Control

strCriteria = "[UserID] = '" & fnOSUserName() & "'"
bAdmin = NZ(DLOOKUP("Admin","tbl_Users", strCriteria), False)
bPower = NZ(DLOOKUP("Power","tbl_Users", strCriteria), False)
bUser = NZ(DLOOKUP("User","tbl_Users", strCriteria), False)

me.AllowAdditions = bAdmin OR bPower
me.AllowDeletions = bAdmin OR bPower

For each ctrl in me.Controls
Select Case Ctrl.Tag
Case "Admin"
ctrl.Locked = NOT bAdmin
Case "Power" 'assumes admin has more rights than Power
ctrl.Locked = NOT (bAdmin OR bPower)
Case "User"
ctrl.Locked = False
Case "User hidden"
ctrl.visible = NOT bUser
Case Else
'do nothing
End Select
Next

End Sub

You have to be careful with setting AllowEdits to false, because this will
affect all of the controls (even unbound ones) on the form.

HTH
Dale
 
Back
Top