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.ScDirectorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.