• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 48
  • Last Modified:

Granting User rights

We have 10 users in our Ms Access application and each is given specific rights by using VBA as below, for example managerial rights:
Private Sub Form_Open(Cancel As Integer)
Dim strITManager As String
strITManager = "Managers"
If Forms!frmLogin!txtUserrights.Value <> [strITManager] Then
MsgBox "You are not authorized to open this form!", vbOKOnly + vbExclamation, "Rights Not Granted"
Cancel = True
Exit Sub
End If
End Sub
The above method works very well with the current XML ribbon, but each and every users will have a chain of buttons which they cannot use or denied access, so instead of using the above VBA I want to hide those buttons that are not required by certain users using a better method if there is any. The challenge here is that I’m using an XML ribbon I do not know whether that can work here, below is a sample:
<button id="PosDelPurchases" imageMso="MasterViewClose" onAction="PosDelPurchases" label="Delete Wrong Purchases"  showImage="true"/>
The above ribbon uses the macros as follows:
(1)      Macro name = PosDelPurchases (onAction="PosDelPurchases")

So in short what I want to hide here is the button id (PosDelPurchases) and the label (label="Delete Wrong Purchases") but authorized users should be allowed to see them.

If the above can work then the software can be easy to use because users will have specific buttons to see and use.

Option available: Since I have seven modules as below could it be okay to create specific ribbons per module and then implement the restrictions at VBA level:
(1)      Entrepreneur
(2)      Sales Accounting
(3)      Purchases Accounting
(4)      Financial accounting
(5)      Inventory
(6)      Budgeting
(7)      Payroll
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
1 Solution
Gustavo BaptistaSSGTCommented:
Hi Christopher,

You can use the getVisible function of the Ribbon Button as so:
<button id="PosDelPurchases" imageMso="MasterViewClose" getVisible="CheckUserRights" onAction="PosDelPurchases" label="Delete Wrong Purchases"  showImage="true"/>

Write the "CheckUserRights" function is the same module where you handle your Ribbon events such as the "PosDelPurchases". In the "CheckUserRights" function simply test if the user has permission to use the button like so:

Public Sub CheckUserRights(Control As IRibbonControl, ByRef Visible As Variant)

If Control.ID = "PosDelPurchases" Then
Visible = .... write a function to check if user has permision and return true if it has, or false if it hasn't...
End If

End Sub

Hope this helps.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now