User permissions in Access 2010

rrhandle8
rrhandle8 used Ask the Experts™
on
How do you create permissions in Access so user "A" and edit data, but user "B" can only view data?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
Nothing is built into Access to handle that.

 Some add a security system in the form of a couple of tables.  One for forms, with a permission flag for Open, Add, Edit, and Delete, and another for controls, with flags for enabling/disabling the controls.

The other way to do it is use a different data store rather than the ACE database engine.  Something like SQL Server, which allows for security on tables and views to be set by user and/or group.

 That doesn't really touch objects though, so most build something in Access.

Jim.
Most Valuable Expert 2012
Top Expert 2014
Commented:
Here's an addon that will do something like that:

http://www.peterssoftware.com/las.htm

As Jim said, it won't do anything for actual data security (users could still go directly to your tables and edit data there), but it does make things a bit easier to control in regard to what users can do on your Forms and such.

Author

Commented:
Thanks guys.  I wonder if I can make this simple.  There are only two user types: full permissions and read only.  Based on the user's login information could I make the database readonly?  Or maybe use a second database just for logging in, and open the database as readonly for particular users?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2012
Top Expert 2014

Commented:
You can set all of your Forms to be ReadOnly when opening them like this:

Me.AllowEdits = False
Me.AllowAddition = False
Me.AllowDeletes = False

This would allow the user to view data, but not modify it.

Of course, if you're allowing users access to your Tables or Queries, then you have no control over that.

Author

Commented:
Scott, possible to loop through all forms when database opens, and set the properties you stated?
Most Valuable Expert 2012
Top Expert 2014

Commented:
You just write them in the Open or Load event of the Form, based on the user login. In most cases, you'd have a hidden form somewhere that would store your "User Level", and your forms could refer to that:

If Forms("Hidden_Form").txtUserLevel > 1 Then
  Me.AllowEdits = True
  Me.AllowDeletes = True
  ect ect
Else
  Me.AllowEdits = False
  etc etc
End If

Or you can do this:

Me.AllowEdits = Forms("Hidden_Form").txtUserLevel > 1

This would set AllowEdits to TRUE if the Userlevel is greater than 1, otherwise it would set it to FALSE.
Distinguished Expert 2017
Commented:
I prefer to use a procedure that locks the individual controls.  This allows the users access to search and filter functions.  If you always want a particular control to be unlocked or locked regardless of the value of bLock, then add either "Lock" or "NoLock" to the tag property.

this code can be used as is.  Add it to a standard module and call it from the Current event of each form you want to control.
If ..... code to determine read only
    Call LockControls(Me, True)
Else
    Call LockControls(Me, False)
End If

Open in new window

Public Sub LockControls(frm As Form, bLock As Boolean)
    Dim ctl As Control
    For Each ctl In frm.Controls
    Select Case ctl.ControlType
        Case acTextBox, acComboBox, acListBox, acCheckBox
            Select Case ctl.Tag
                Case "NoLock"
                    ctl.Locked = False
                Case "Lock"
                    ctl.Locked = True
                Case Else
                    ctl.Locked = bLock         'toggle locks
            End Select
        Case acOptionGroup, acOptionButton, acCheckBox      ''not working
             Select Case ctl.Tag
                Case "NoLock"
                    ctl.Locked = False
                Case "Lock"
                    ctl.Locked = True
                Case Else
                    ctl.Locked = bLock         'toggle locks
            End Select
        Case acCommandButton
            Select Case ctl.Tag
                Case "NoLock"
                    ctl.Enabled = True
                Case "Lock"
                    ctl.Enabled = False
                Case Else
                    ctl.Enabled = Not bLock         'toggle locks
            End Select
    End Select
Next ctl
Set ctl = Nothing
End Sub

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial