User restrictions

lulugreg

New Member
Joined
Sep 25, 2006
Messages
32
Hello,

Is it possible to let all users SEE the database, but restrict to two or three specific users who can actually input into anything?

If so, please can you tell me how?

Many thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Yes, it is possible.
You need to look into Tools/Security. Under that, you would set up a Workgroup and then identify the users and groups allowed to use that particular db. You also need to set permissions. This is where you would define RO and RW abilities.

I don't have any books on MS Access Security to point you to, but you have to learn up on that in order to accomplish what you want to do.

I guess you code write VBA code also, but if you're not using the Security feature, Access defaults to all users accessing a db as Admin and without some foolproof way of doing it, writing code would have it's drawbacks.
 
Upvote 0
This is a method that I have used successfully. You will need:

1. A table called tblStaff, with at least the fields Login and Permissions. Both are Text fields.
(a) In Login, enter the Windows login name of each user who will have ability to add or change data. Those whose names do not appear here will have read-only access to the database.
(b) In Permissions, give them values Edit or Admin

2. A form that opens as your main menu. In this example the form is frmMenu. On this form you need 2 hidden textboxes called txtUser and txtLevel.
In the Form's Load event you will need this code:
Code:
Private Sub Form_Load()
    Dim sPermit As String
    Dim iAccess As Integer
    Dim Ctl As Access.Control
    Me.txtUser = Environ("username")
    If IsNothing(Me.txtUser) Then
        sPermit = "ReadOnly"
    Else
        sPermit = GetPermission(Me.txtUser)
    End If
    Select Case sPermit
        Case "Edit"
            iAccess = 2
        Case "Admin"
            iAccess = 3
        Case Else
            iAccess = 1
    End Select
    Me.txtLevel = iAccess
End Sub

Private Function GetPermission(sUser As String)
    If (IsNothing(DLookup("Permissions", "tblStaff", "Login='" & Forms!frmmenu!txtUser & "'"))) Then
        GetPermission = "ReadOnly"
    Else
        GetPermission = DLookup("Permissions", "tblStaff", "Login='" & Forms!frmmenu!txtUser & "'")
    End If
End Function
If you don't know how to do this, here's how:
Go to the form's Properties.
Click the Events tab.
Double-click the blank Load row, so you see Event Procedure.
Click the Builder (...) button to go to the code window.
Paste this code in, replacing this stuff:
Code:
Private Sub Form_Load

End Sub
With the code you copied.

3. On each form that opens you need this in the Form_Load event:

Code:
If forms!frmMenu!txtLevel = 1 Then
   Me.AllowEdits = False
Else
   Me.AllowEdits = True
End If
Denis
 
Upvote 0
Thank you both for your replies and help! I will have a good study of your suggestions and let you know how I get on!

Thanks again

Linda
 
Upvote 0
Could you modify the switchboard?

You know Denis, this is an awesome script! I would like to know if it would be possible to add this the an existing switchboard, so when the database opens, it runs this script when the switchboard is opened? What do you think? Any suggestions?

Regards,

~~Bradley

This is a method that I have used successfully. You will need:

1. A table called tblStaff, with at least the fields Login and Permissions. Both are Text fields.
(a) In Login, enter the Windows login name of each user who will have ability to add or change data. Those whose names do not appear here will have read-only access to the database.
(b) In Permissions, give them values Edit or Admin

2. A form that opens as your main menu. In this example the form is frmMenu. On this form you need 2 hidden textboxes called txtUser and txtLevel.
In the Form's Load event you will need this code:
Code:
Private Sub Form_Load()
    Dim sPermit As String
    Dim iAccess As Integer
    Dim Ctl As Access.Control
    Me.txtUser = Environ("username")
    If IsNothing(Me.txtUser) Then
        sPermit = "ReadOnly"
    Else
        sPermit = GetPermission(Me.txtUser)
    End If
    Select Case sPermit
        Case "Edit"
            iAccess = 2
        Case "Admin"
            iAccess = 3
        Case Else
            iAccess = 1
    End Select
    Me.txtLevel = iAccess
End Sub

Private Function GetPermission(sUser As String)
    If (IsNothing(DLookup("Permissions", "tblStaff", "Login='" & Forms!frmmenu!txtUser & "'"))) Then
        GetPermission = "ReadOnly"
    Else
        GetPermission = DLookup("Permissions", "tblStaff", "Login='" & Forms!frmmenu!txtUser & "'")
    End If
End Function
If you don't know how to do this, here's how:
Go to the form's Properties.
Click the Events tab.
Double-click the blank Load row, so you see Event Procedure.
Click the Builder (...) button to go to the code window.
Paste this code in, replacing this stuff:
Code:
Private Sub Form_Load

End Sub
With the code you copied.

3. On each form that opens you need this in the Form_Load event:

Code:
If forms!frmMenu!txtLevel = 1 Then
   Me.AllowEdits = False
Else
   Me.AllowEdits = True
End If
Denis
 
Upvote 0
Hi Bradley, glad you like it! :biggrin:

I haven't found a way to do this with a Switchboard but here's the rest of my setup -- this uses a single textbox on the menu form, which I call lstLauncher.

You will need:
1. A table called MenuItems, with these fields --
Book1
ABCD
1MenuItemstable
2
3FieldDataTypeComment
4ItemTextDescriptivename
5FormTextObjectname(realnameindb)
6ObjectTypeTextFormorReport
7SortOrderNumberUsedtosetorderinlist
Sheet1

2. The listbox called lstLauncher, with this RowSource --
Code:
RowSource for listbox (lstLaunch)

SELECT MenuItems.Item, MenuItems.Form, MenuItems.ObjectType FROM MenuItems ORDER BY MenuItems.SortOrder;

3. In the Click event of the listbox, this code --
Code:
OnClick event for list box (lstLaunch)

    Dim sForm As String, sType As String
    sForm = Me.lstLaunch.Column(1)
    sType = Me.lstLaunch.Column(2)
    Select Case sType
        Case "Form"
            DoCmd.OpenForm sForm
        Case "Report"
            DoCmd.OpenReport sForm, acViewPreview
    End Select
You control what users can go to by adding records to MenuItems.
Control the order of the list by edting the SortOrder field.
When users click, the code checks whether the object is a form or report, and runs the appropriate action.
If you also need to launch queries, add another Case statement to the OnClick event to deal with them.

Denis
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top