Ribbon and user privileges. (1 Viewer)

Status
Not open for further replies.

deletedT

Guest
Local time
Today, 21:58
Joined
Feb 2, 2019
Messages
1,220
This post is an extention to The enduring nature of Access. While showing some images of my applications' ribbons to prove ribbon is far better , flexible and much more easier to communicate with, than traditional menus, I was asked (by jdraw) to show how I do it.
I promised him to set up a simple database during our summer holidays, but today I was free about an hour. So I made a simple database to show how it can be done.

Since I didn't want to high jack that thread, I started a new one.
Mods can delete/move/merge/correct this post if they find it appropriate.

Note: Posting all the contents in one post, makes it so long and hard to understand. I split it into several posts. The title of each post shows what it is about. If you don't need to read that section, simply go to the next one.

The sample database is attached to the last post.I don't know how deep I should go in explaining ribbons and I know most of active members here know much more than me or what is needed, but I think I have to explain several basic points for those who are challenging with ribbons for the first time.
 
Last edited:

deletedT

Guest
Local time
Today, 21:58
Joined
Feb 2, 2019
Messages
1,220
Several important points before you start:

  • I said it would have more than several thousands line of codes, but to make it easy to understand, I cut down a lot of its functionality. My ribbons do much more than what is shown here. But for now, I think it's enough to show Ribbons are much smarter than traditional menus.
  • If you want to be able to harness ribbon, you should know how exactly a ribbon works. It means it's not enough to create your ribbon. You should know how exactly access shows it.
  • The sample database is written in Office 365 64 bit. If the version doesn't work for you, ask somebody to do the necessary modification to work with 32 bit of office.
  • This post is not meant to show how to create your ribbon. The sole aim of this Thread is to show how to control your ribbon with user levels. Which user is allowed to do that, Which user is banned to do this.
  • There are a lot of ways to create a ribbon in MS Office. What I show bellow works with any of them. Just create your own ribbon and follow bellow.
  • I don't claim what I do bellow is correct. I never had a good education and haven't attend school since I was 13. I had to work hard for a living. I will post something about myself later. Every piece of what is written bellow is just a result of months and years of reading online articles, samples and testing different ways to combine them and accomplish what I need my application do. So before accepting what's told bellow, research for yourself. Let the following be a hint, not a solution. Because to be true, I'm not sure if it's correct or not. It only works.
 
Last edited:

deletedT

Guest
Local time
Today, 21:58
Joined
Feb 2, 2019
Messages
1,220
Basic points of ribbons:

  • Ribbon source code is in xml.
  • We can create a xml string and pass it to Access (Or any MS Office application) and ask Access to use this xml as the ribbon for current application (instead of the default one).
  • Ribbon is made of one or several tabs. Each tab contains one or several Groups. Each Group contains controls.
  • Each object in a ribbon, just like other objects in forms, has a lot of properties that can be set in XML. There are a lot, but what we need here to be able to work it with user level is id, label, size, image, OnAction, Visible, Enabled.
  • Every control should have a specific ID. Same ID can't be use for different controls. It means if your ribbon has 100 controls, you must have 100 different IDs.
  • Access doesn't run the whole XML file to create the ribbon. It runs ONLY the current tab. Imagine you have a ribbon with 8 tabs. When you pass the XML to Access to show your ribbon, Access runs the default tab section only. When you click the second tab, Access runs the XML for that tab. Once a tab is produced, Access doesn't run that section anymore and simply shows it. In other words, if one of your tabs has an error in XML, you don't receive the error until you click the tab to make Access execute that section of XML.
  • There is two ways to control your ribbon with logged in user.
1- You can do login process and then create your XML according to the user level and pass it to Access.
Or
2- You can create a XML for all users. Do login process and hide/show controls according to what the logged in user is allowed to do.

Since the second method is easier to understand, I go with the second one in this post. Once you understand how it is done, you can change to the first one easily. (I may post an example of the first one too.)
 
Last edited:

deletedT

Guest
Local time
Today, 21:58
Joined
Feb 2, 2019
Messages
1,220
First Step: Create your XML

We can set visibility and other properties of controls in XML. For example: Visible=true.
But because we want to control the visibility of all controls according to different situations (different users) we set a function to be executed.
It means:

Instead of Visible=True we use:
getVisible="GetVisible" GetVisible in red is the name of a function in vba (You can choose a different name). We ask access to run GetVisible function to find out if this control is going to be hidden or visible. .

Instead of Enabled=Yes we use:
getEnabled="GetEnabled" GetEnabled in red is the name of a function in vba (You can choose a different name). We ask access to run GetEnabled function to find out if this control is going to be enabled or locked.

Instead of Lable="Print Report" we use:
getLabel="GetLabel" GetLabel in red is another function (You can choose a different name). I'm asking Access to run GetLabel function to find out what the caption of the control is. It's because I want to show different captions of the same control for different users.


Instead of OnAction="MyPersonalFunctio" we use:
onAction="OnActionButton" OnActionButton in red is another function. I'm asking Access to run OnActionButton function to when the button is clicked.(You can use a different name for your ribbon)

All said, my XML code to add a button to my ribbon is:
<button id="btn_Receiption_Set" size="large" getLabel="GetLabel" imageMso="TableOfContentsDialog"
onAction="OnActionButton" getVisible="GetVisible" getEnabled="GetEnabled"/>



The same goes with other controls.

When your XML file is ready, we are done with this step.
Hint:
I save my XML file in a table to be able to control it. You can do others methods.
 
Last edited:

deletedT

Guest
Local time
Today, 21:58
Joined
Feb 2, 2019
Messages
1,220
Manage your database to be able to control ribbon:

I have a table to list the Restricted users.







Note: The above image in the latest version is a bit different. But the concept is the same.

Because the number of controls are too much I only register the restricted ones.
As you see in the above image, I don't want to show tab_Admin, btn_Begins_with_Filter and several other controls to user 18.

How does it work:
When application is launched, LoadRibbon function is executed. XML code for ribbon is generated and is passed to Access. Access runs it, and for each control, GetVisible function is executed. (because the visibility of all controls in XML is set to this function.

When you launch the database, because GetVisible can't find a valid login, it hides all tabs except the first one. This tab contains only login & Exit buttons.
After a successful and valid login, I ask Access to delete and rebuild the ribbon. Because I want to hide this tab and show/hide other tabs & controls:

ReceiptionRibbon.Invalidate

(ReceiptionRibbon is the name of my ribbon. You should use your own ribbon name.)
Access rebuilds the ribbon. This time because GetVisible finds a valid login, searches tblUserRestrictions for current user for each control to see if a record for this ID exists.
Imagine user 18 logs in. Access runs GetVisible for every control in the current tab. If it finds a record that matches the current controlID and current user & HideThisCtrl is set to YES, the visibility is set to false. If no record is found, the visibility is set to true.

The same goes for other properties, getEnabled, getLabel etc.

Now I have the power to hide\show different controls for different users, Show different captions for different users, and even execute different functions by clicking the same button for different users.

I'm able to show/hide single/multiple tabs, groups, controls for different level of users.
 

Attachments

  • 1.jpg
    1.jpg
    23.3 KB · Views: 685
  • 2.jpg
    2.jpg
    43.8 KB · Views: 672
Last edited:

deletedT

Guest
Local time
Today, 21:58
Joined
Feb 2, 2019
Messages
1,220
How to test the database:
Launch database.
Select Tera from combo box and click login button.
Tera is the admininistator of the database. All tabs and all controls are visible, Language is set to English.
Pay close attention to the right tabs. Admin And Form Design.
Click Master Tab.
Pay close attention to the Customer Group. (following image)



Click home tab.
Click User Log out.
Select Ando from User list.
Click Login.

you'll see Admin & Form Design tabs are hidden.
Click Master tab
You'll notice the Customer group and 10 buttons are hidden. He's restricted for customer.
Clic Search Tab.
He has srch Purchased button:




Click home tab.
Click User Log out.
Select Ikeda from User list.
Click Login.
Click search. You'll see Search Purchased is hidden. He's restricted for this control


As the last test:
Log out and login as Saito
Wow. now everything is in Japanese.


If you want to hide/show enable/disable other controls for different users, login as Tera. Click Admin tab, then click Export Ribbon Button.
You'll receive a XML of the whole ribbon. Find the ID of the object you want to control.
Open tblUserRestrictions table, add a new record, type the ID you want to control, type the userID and tick HideThisCtrl if you want to hide it for that user or DisableThisCtrl if you want to disable it.
Close database, Open it and login to see how the ribbon show.

Now I have a multi language, user wise application. :)
 

Attachments

  • 3.jpg
    3.jpg
    51.6 KB · Views: 676
  • 4.jpg
    4.jpg
    50.9 KB · Views: 667
  • RibbonExample.zip
    479.6 KB · Views: 367
Last edited:

isladogs

CID VIP
Local time
Today, 21:58
Joined
Jan 14, 2017
Messages
14,038
Tera
Thanks for posting this guide.
As requested I've restored the thread and moved it to Sample databases so its easier for others to find
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:58
Joined
Oct 29, 2018
Messages
13,332
Hi Tera. Thanks! This is really going to be very useful to those who want to try out using Ribbons. Cheers!
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom