Question how to change fields values by only the admin in access2016 (1 Viewer)

akika

Registered User.
Local time
Today, 03:48
Joined
Aug 7, 2018
Messages
102
hi,
Pls help.
in access 2016, I have field ' assigned_to' & 'project_cost' in the database and form.
how can i make this these fields be amendable by only the admin user.

for security level, i have admin, normal user.. both of these user type will have access with the form containing these fields but only admin need to change those.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:48
Joined
Feb 28, 2001
Messages
27,001
Akika,

To accomplish this, you need to set up the DB so that your users NEVER see the infrastructure i.e. the ribbon and object navigation panel. You need to have a table of usernames and then associate the usernames to specific roles.

The payoff is that if you have that, then on the relevant form, in that form's OnLoad event, you could put code that set .Locked=True or .Locked=False based on the user's role. e.g. in the form's class module:

Code:
Private Sub Form_Load()

Dim UName as String
Dim URole as Long

...
    UName = Environ("Username")
    URole = DLookup( "[UserRole]", "usertable", "[UserRole]='" & UName & "')

    IF URole = 1 Then
        [Assigned_To].Locked = FALSE
        [Project_Cost].Locked = FALSE
    Else
        [Assigned_To].Locked = TRUE
        [Project_Cost].Locked = TRUE
    End If

End Sub

You can embellish this, but the assumption is that admin role code is 1 and the normal user role code is something else (including 0 and not defined). So you look up the user's role and if it is 1, unlock things. If not, lock them.

You can search this forum for "Securing a database" to see the kinds of things you need to do to prevent your users from getting into the innards of the DB. If you don't do this, you CANNOT protect those data items.
 
Last edited:

MarkK

bit cruncher
Local time
Today, 03:48
Joined
Mar 17, 2004
Messages
8,178
Selectively lock or disable the controls based on the security level of your user. You have not told us anything about how your user is represented in your data so this is a guess, but something like...
Code:
Private Sub Form_Open(Cancel as Integer)
[COLOR="Green"]    ' lock...[/COLOR]
    Me.AssignedTo.Locked = Not YourSystemUser.SecurityLevel = "Admin"
[COLOR="green"]    ' or disable...[/COLOR]
    Me.ProjectCost.Enabled = Your SystemUser.SecurityLevel = "Admin"
End Sub
hth
Mark
 

Users who are viewing this thread

Top Bottom