Role-based access MS Access2016 (1 Viewer)

aamyra

New member
Local time
Today, 17:32
Joined
Apr 28, 2022
Messages
8
hello,
when a user opening access, it should be able to access the form according to the roles
The table name is tblUser and the users are General User, HR, and Admin.
Currently, In the table I have the roles assigned number with GeneralUser (read-write) = 1, HR(Read-only) = 2, Admin(Full access) = 3.
table structure: Name, ID, Roles ID, Roles Desc

How to do that?
For e.g user Amyra Full access to view, read-write in the form
JohnSmith read-only
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 02:32
Joined
Jan 20, 2009
Messages
12,852
For this kind of security you would be better off using an SQL Server backend where permissions are intrinsic.
 

aamyra

New member
Local time
Today, 17:32
Joined
Apr 28, 2022
Messages
8
For this kind of security you would be better off using an SQL Server backend where permissions are intrinsic.
i have only ms access to do this.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:32
Joined
Sep 21, 2011
Messages
14,263
Store the user level when they log on into a Tempvar/global variable.
Set form access levels on form load.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:32
Joined
Sep 21, 2011
Messages
14,263
I actually used a switchboard form and the user level dictated what options were available, so I did not have to add code to all the forms, just the switchboard table.
In my login form, I also supplied a combo with allowed users.
I know that makes cracking the password easier, but we were in a simple environment with trustworthy employees, plus it was for managers only, plus myself.
Code:
    TempVars("EmployeeID").Value = Me.cboEmployeeID.Column(0)
    TempVars("Employee").Value = Me.cboEmployeeID.Column(1)
    TempVars("UserLevel").Value = DLookup("DataOrder", "tblLookup", "LookupID = " & Me.cboEmployeeID.Column(3))
    DoCmd.OpenForm "Switchboard"
    DoCmd.Close acForm, strFormName
 

isladogs

MVP / VIP
Local time
Today, 17:32
Joined
Jan 14, 2017
Messages
18,213
I also have an example password login app with different user levels:
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:32
Joined
Feb 28, 2001
Messages
27,171
In general, using "pure" Access as opposed to a foreign back-end, you are obliged to "roll your own" security. Search this forum for MANY articles on these topics:

Role-based security
Securing a database
User roles

Unfortunately, back in 2003, the problem with User-Level security in Access had grown to be such a problem that they deprecated the ability. At the time, the U.S. Dept. of Defense listed MCAS (the Microsoft Computer Access Security module that implemented User Level security) as one of the top 10 security threats to any computer-based organization. It was buggier than a spring termite swarm. Now, even if you had everything else you needed, modern versions of Access won't acknowledge the settings of an MDW file even if you have the system setup to run MDB files.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:32
Joined
Feb 19, 2002
Messages
43,257
Here's another sample of simple security. It uses four security options - View, Edit, Add, Delete with values ranging from 0-9
Then each form is assigned four security options for View, Edit, Add, Delete. In each form, the user's security options are matched to those of the form. For example, code in the form's BeforeInsert event compares the "Add" values for the user to the form. The BeforeUpdate event compares the "Edit" values, the OpenEvent compares the "View" options and the OnDeleteConfirm event compares the "Delete" values. Any subforms or popups must default to the same security as the form that spawned them unless you want to make a more complicated setup.

 

aamyra

New member
Local time
Today, 17:32
Joined
Apr 28, 2022
Messages
8
I actually used a switchboard form and the user level dictated what options were available, so I did not have to add code to all the forms, just the switchboard table.
In my login form, I also supplied a combo with allowed users.
I know that makes cracking the password easier, but we were in a simple environment with trustworthy employees, plus it was for managers only, plus myself.
Code:
    TempVars("EmployeeID").Value = Me.cboEmployeeID.Column(0)
    TempVars("Employee").Value = Me.cboEmployeeID.Column(1)
    TempVars("UserLevel").Value = DLookup("DataOrder", "tblLookup", "LookupID = " & Me.cboEmployeeID.Column(3))
    DoCmd.OpenForm "Switchboard"
    DoCmd.Close acForm, strFormName
u have a sample project for reference?
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:32
Joined
Sep 21, 2011
Messages
14,263
No, sorry, not without extracting what is required. I also put in a tweak to make it a little more difficult to work out who could do what, and that might confuse you.
I'd go with Pat Hartman's model. It will definitely be more robust than mine. :)
 

KitaYama

Well-known member
Local time
Tomorrow, 01:32
Joined
Jan 6, 2022
Messages
1,540
I also put in a tweak to make it a little more difficult
I'd really like to see how it works.
No need for details. Just a simple explanation (even in a separate thread) is appreciated.
 

aamyra

New member
Local time
Today, 17:32
Joined
Apr 28, 2022
Messages
8
am still struggling with that login and make the users have the read-only or able to change the field values.... :cry:😕
is there a more simple way to do that?
when user click on the access to open it get authenticate and the form open based on the security level.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:32
Joined
Feb 19, 2002
Messages
43,257
You've had several suggestions. Which one are you trying to implement?

Post YOUR version of the code and tell us what is or is not happening.
 

Users who are viewing this thread

Top Bottom