Limit user access to certain forms or reports (1 Viewer)

hfsitumo2001

Member
Local time
Today, 13:26
Joined
Jan 17, 2021
Messages
365
Helo, Anyone can help me how to make that certain users can only access certain forms or reports. In my login table I have:
  1. UserID
  2. UserName
  3. Password
  4. Accesstype
Thank you

Frank
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:26
Joined
Oct 29, 2018
Messages
21,469
In the Open event of your form, check the user's permission and either continue to open the form or show a message box and cancel the form from opening.
 

hfsitumo2001

Member
Local time
Today, 13:26
Joined
Jan 17, 2021
Messages
365
In the Open event of your form, check the user's permission and either continue to open the form or show a message box and cancel the form from opening.
Thanks George, but I do not know what is the VBA for this, probably lookup the table and the User access type and than say if.... then open, other Msg Box.

Thank you

Frank
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:26
Joined
Sep 21, 2011
Messages
14,274
This is more to authorize to the table, but I want to start opening a form thru my switchboard menu, then there will be a check on opening the form.

Thank you
I have never seen the logic of presenting a user with a choice, only to say they cannot use it, when they try to do so?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:26
Joined
Feb 19, 2002
Messages
43,266
I've posted this sample a few times. It might help you. It is a custom switchboard that expands on the concept of the old Access Switchboard and incorporates some basic security options. Each switchboard item is assigned add, change, delete, view properties ranging in value from 0-9. Each user is assigned add, change, delete, view properties from 0-9. In the appropriate event of the form, the level required to use the form option is compared to that of the user. So if a form requires level 5 for allowing change, the Form's on Dirty event would compare the user's change level to 5 and if the user level was <= 5, the code would proceed. Othewise, the update would be cleared (Me.Undo) and a message would be returned to the user telling him he did not have the authority to update this form. If the user is trying to delete a record, the validation code for delete would be in the BeforeDelete event, etc.

Take a look and see if you think it might work for you.
 

Attachments

  • SwitchboardForm20201104.zip
    1.6 MB · Views: 387

EdwardsC

New member
Local time
Today, 13:26
Joined
Jul 10, 2019
Messages
21
In a separate table, define what user levels has access to your forms using a yes no field. The employee can simply login and the employee ID can be saved as a temporary variable. Each form can have a DLookup to that looks for the employee and whether that particular employee has access to the form being opened.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:26
Joined
Feb 19, 2002
Messages
43,266
I guess you didn't look at the sample I posted. It is simplistic but will probably work for you. If you want to do this by making specific rules for each user, you should probably move up a level and create user Groups to save yourself a lot of work. That way you would define permissions for a group and then assign users to groups. That is the way Windows works.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:26
Joined
Feb 28, 2001
Messages
27,175
how if we want it to be more than one form or report.

You have one user table with some indicator of each user's role. It could be "Admin" or "Supervisor" or "Auditor" or "Mechanic" or ... whatever things your employees do. You could use a code instead of a role name. Immaterial to the process, just be consistent in how you use it.

If you have a login form, or if you use an Opening Form to be a dispatcher or switchboard, you look up the user role based on the user ID. Store that either in a public variable in a general module or in a TempVar. Your choice as to which method you wish to use. But you keep that value where it is usable for as long as that user's session is active. Erase that info when the user logs out, unless Access is also exiting at that time. In which case everything is being erased anyway.

Then you decide for each form/report ... FOR EACH ONE INDIVIDUALLY ... which roles should have access to that form/report.

Then for each one item, you have the Form_Open or Report_Open event look at the user's information in that place where you stored the role.

Then you have, in each _Open routine,

Code:
IF UserRole <> "Admin" AND UserRole <> "Supervisor" THEN
    Cancel = 1
    Exit Sub
End If
.... other things that the _Open routine might need to do...

There are fancier ways but if you have multiple roles, multiple forms, and multiple reports, and there is no uniformity, you have to do SOMETHING individual and therefore a bit tedious.
 

Users who are viewing this thread

Top Bottom