permissions based on user table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a user table tbl_users with a bunch of users. There are 3 access
levels on my switchboard and on all forms in the form footer I have the
user_id and access level (number) shown. I want to make forms read only or
write and read only depending on the access level of the user.

Therefore I would have something like this:

if me.access = 1 then
give all access (tables, forms, reports etc)
else

end if

if me.access= 2 then
give write access (however do not let person do design or display database
window)
else

end if

if me.access=3 then
give read only access (user can only see forms as read only and access
reports)
else

end if



I also have my userid and access on a hidden form. So we could drive it
from there.

If forms!invisibleuserid.userid = 1 then
give all acccess
else

end if

etc etc etc.

Any one has any idea as to access levels and how to program it? Either
locking all fields. I want something fairly easy in terms of code that I
could put on my invisibleuserid form that would either
 
OK, I think I have figured out how to do this, however my form is not working
properly.

for my from frmcontactforpaylist I have the following code in the form's
current event:


Private Sub Form_Current()
If Me.level = 1 Then
Form.AllowAdditions = False And Form.AllowEdits = False And
Form.AllowDeletions = False And Form.AllowDesignChanges = True And
Form.AllowFilters = True
Else
If Me.level = 2 Then
Form.AllowAdditions = True And Form.AllowEdits = True And
Form.AllowDeletions = True And Form.AllowDesignChanges = False And
Form.AllowFilters = True
Else
If Me.level = 3 Then
Form.AllowAdditions = False And Form.AllowEdits = False And
Form.AllowDeletions = False And Form.AllowDesignChanges = False And
Form.AllowFilters = True
End If
End If
End If

End Sub

This should work I believe, yet if I open the form and my access is 1 or 3,
I can still make edits on the form.
 
Jean-Francois Gauthier said:
Private Sub Form_Current()
If Me.level = 1 Then
Form.AllowAdditions = False And Form.AllowEdits = False And
Form.AllowDeletions = False And Form.AllowDesignChanges = True And
Form.AllowFilters = True

Lose the 'Ands'

If Me.level = 1 Then
Form.AllowAdditions = False
Form.AllowEdits = False
Form.AllowDeletions = False
Form.AllowDesignChanges = True
Form.AllowFilters = True
etc.
 
Just a minor aside...
If Me.level = 1 Then

It is generally a good idea, to avoid confusion if not outright errors, to
recognise the following Access VBA syntax:
Me!<field>
Me.<operator>

It may not matter sometimes, but then Access has tightened up on this usage in
more recent versions.
(if Intellisense Help does not show "level" after placing the dot, then it is
not strictly valid syntax. Something like that, someone else probably knows
more :-) )

(if it didn't catch you out this time, strict syntax will soon enough)

Chris
 
Back
Top