UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Hiding Ribbon Groups With VBA, Access 2016    
 
   
mscola
post Oct 5 2018, 06:45 AM
Post#1



Posts: 25
Joined: 24-July 13



Hi all

Is there an easy way to hide and unhide Ribbons groups and hence the other objects on/in that group?

I have to create an database which different people will have Access to. Based on the login, only certain groups should be shown.
For example, an admin should see all groups, while an Employee can only see the home group and the employee group.

My example Ribbon has the following three groups to start with:

grpHome
grpAdmin
grpEmployee

in the tab called:

Home

I have created the Ribbons using RibbonCreator.

Can anyone guide me or show/give me an example how to best tackle this problem?

Thanks

MassimoAttached File  Employees__1_.zip ( 67.83K )Number of downloads: 5

Go to the top of the page
 
theDBguy
post Oct 5 2018, 07:53 AM
Post#2


Access Wiki and Forums Moderator
Posts: 73,773
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Not in front of a computer right now but have you looked at the Invalidate call back?

Sent from phone...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
mscola
post Oct 5 2018, 08:11 AM
Post#3



Posts: 25
Joined: 24-July 13



No not yet - I have read that buttons can be invalidated.

I just need to find an example on how this can be done.
My Knowledge regarding Ribbons is about creating the Ribbon + call backs.

I am glad to hear that it is possible to hide and show groups.
My understanding is that only one Ribbon can be loaded at a time with Access.
This post has been edited by mscola: Oct 5 2018, 08:12 AM
Go to the top of the page
 
pere_de_chipstic...
post Oct 5 2018, 11:51 AM
Post#4


UtterAccess Editor
Posts: 10,326
Joined: 8-November 07
From: South coast, England


PMFJI

You need to include the getVisible callback in the group's ribbon XML code, e.g.
CODE

<group id="grpGetLogo" getVisible="rbnGetVis" label="Your Group Name">
...
...
</group>


in your calling code set a variable (Here a TempVar) to determine the visibility, and then invalidate the group e.g.
CODE
    TempVars.rbnGrpVis = -1   '(to set the group visible or  = 0 to hide it  )
    gobjRbn.InvalidateControl "grpGetLogo"


The callback sub would then read (e.g.):
CODE
Sub rbnGetVis(ctrl As IRibbonControl, ByRef Visible)
   Visible = Cbool(TempVars.rbnGrpVis)
End sub


hth
This post has been edited by pere_de_chipstick: Oct 5 2018, 11:52 AM

--------------------
Warm regards
Bernie
Go to the top of the page
 
pere_de_chipstic...
post Oct 5 2018, 11:57 AM
Post#5


UtterAccess Editor
Posts: 10,326
Joined: 8-November 07
From: South coast, England


PS

I believe you can load more then one ribbon at a time by setting the start from scratch xml code line to false at the start of the ribbon code:
CODE
<ribbon startFromScratch="false"


Though I have only ever used <ribbon startFromScratch="true" > and you'd need to experiment!

--------------------
Warm regards
Bernie
Go to the top of the page
 
mscola
post Oct 10 2018, 02:53 AM
Post#6



Posts: 25
Joined: 24-July 13



Apologies for the late Reply. I will try the code right now.

@theDBguy: My understanding of Ribbons with Access is, that if you want to load a different Ribbon, Access needs to be restarted. Please correct me if I'm wrong.
Go to the top of the page
 
mscola
post Oct 10 2018, 03:41 AM
Post#7



Posts: 25
Joined: 24-July 13



pere_de_chipstick:

I have tried your code ... where is the calling code for the ribbon?
You wrote that I should add the following code to the calling code:

CODE
TempVars.rbnGrpVis = -1   '(to set the group visible or  = 0 to hide it  )
    gobjRbn.InvalidateControl "grpGetLogo"


Where is the calling code for the Ribbon?

Is it:

CODE
Sub OnRibbonLoad(ribbon As IRibbonUI)


The issue might also be the TempVar.
Don't I Need to declare the TempVar first before I can use/access it?
Wouldn't I have to create something like this:

CODE
Dim rbnGrpVis As TempVar


Unfortunately, this doesn't work.

I would really appreciate it if you could help me out with this, as this issue has been giving me headache for some time. And I also think that your solution will most likely work.

Thanks for your help

Massimo
Go to the top of the page
 
pere_de_chipstic...
post Oct 10 2018, 05:09 AM
Post#8


UtterAccess Editor
Posts: 10,326
Joined: 8-November 07
From: South coast, England


Hi Massimo

The calling code is the code which is triggered when you want some aspect of the ribbon to change e.g. when you want to hide or unhide the ribbon group; if, for instance, you used a checkbox on a form to change the visible status of the group, then the checkbox itself could be used to store the variable and its after_update event would be (e.g.)
CODE
Private Sub chkGrpVis_AfterUpdate()
    gobjRbn.InvalidateControl "grpGetLogo"
End Sub


and the getVisible call back would be (e.g.)
CODE
Sub rbnGetVis(ctrl As IRibbonControl, ByRef Visible)
   Visible = Forms!YourFormName!chkGrpVis
End sub


The OnRibbonLoad Callback is used for establishing a ribbon variable which can be referred to in your code e.g.
CODE
Public gobjRbn  As IRibbonUI

Public Sub onRibbonLoad(ribbon As IRibbonUI)
     Set gobjRbn = ribbon               '
End Sub

Once the ribbon variable has been set, it can be referenced in your code as in gobjRbn.InvalidateControl "grpGetLogo" (above)

If you use a TempVar then you need to declare it:
CODE
TempVars.AddNew "rbnGrpVis ", "0"
Note that TempVars are stored as stored as strings hence the Visible = Cbool(TempVars.rbnGrpVis) in my code above.

Finally, you can have multiple ribbons and you can swap them by amending the form's ribbon property using VBA code, though I wouldn't recommend this - it is better to change the properties of the ribbon controls (visible, enabled, text etc) in most cases.
You cannot amend the usysRibbons table without restarting Access for the changes to take effect.

hth
This post has been edited by pere_de_chipstick: Oct 10 2018, 05:12 AM

--------------------
Warm regards
Bernie
Go to the top of the page
 
mscola
post Oct 10 2018, 07:01 AM
Post#9



Posts: 25
Joined: 24-July 13



Thank you so much for your help and for your patience.
I am doing this for the first time and just Need some guidance.

I will try your code this afternoon. Hopefully it will work :-)

Just one more question: If I can hide and show groups and text, can I do the same with tabs with VBA?

I hope this question is useful to other people who want to implement the same functionality in their project.

Massimo
Go to the top of the page
 
pere_de_chipstic...
post Oct 10 2018, 09:04 AM
Post#10


UtterAccess Editor
Posts: 10,326
Joined: 8-November 07
From: South coast, England


Hi Massimo

Yes, you can control the visibility of tabs with VBA, you should ensure that the XML for the tab control includes the getVisible callback. Texts normally hide / unhide with the control they are attached to, if you want to change the texts on a label then the control needs to include a getLabel callback.

There is also a label control (labelControl) that is independent of another control, which has getLabel and getVisible callbacks available

hth

--------------------
Warm regards
Bernie
Go to the top of the page
 
mscola
post Oct 10 2018, 10:07 AM
Post#11



Posts: 25
Joined: 24-July 13



Hi Bernie

I have implemented the following so far:

I have added

CODE
Public gobjRbn  As IRibbonUI

Public Sub onRibbonLoad(ribbon As IRibbonUI)
     Set gobjRbn = ribbon               '
End Sub


and

CODE
Sub rbnGetVis(ctrl As IRibbonControl, ByRef Visible)
   Visible = Forms!MyForm!chkGrpVis
End Sub


to the module called basRibbonCallbacks

and I have added

CODE
Private Sub chkGrpVis_AfterUpdate()
    gobjRbn.InvalidateControl "grpGetLogo"
End Sub


to the Form.

This is where I get an error message, saying that an object is required.
After I have typed gobjRbn. IntelliSense should show the possible functions, right?
It doesn't - unless I add Public gobjRibbon As IRibbonUI to the form.
But it is a public variable .. a global one right? .. so it should work everywhere.

I do not know what I am doing wrong.

I am currently doing an internship and I have been asked to create an EmployeeDB.
I already have the data model, the system documentation etc.. so I am now at the user interface part.
If I am doing well, I might get a job in the IT Department. Certain parts of VBA are new to me,
as I'm more familar with Java, JavaScript etc.

That's why I really appreciate your help.

Would you be so kind as to have a look at my DB and tell me what I am doing wrong?

Thanks a lot

Massimo





Attached File(s)
Attached File  EmployeeDB.zip ( 81.77K )Number of downloads: 5
 
Go to the top of the page
 
theDBguy
post Oct 10 2018, 10:35 AM
Post#12


Access Wiki and Forums Moderator
Posts: 73,773
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Re: "@theDBguy: My understanding of Ribbons with Access is, that if you want to load a different Ribbon, Access needs to be restarted. Please correct me if I'm wrong."

If you're referring to the application-wide custom ribbon, then I think you're right. However, it is possible to assign a different ribbon to a form at runtime. Not exactly what you're looking for, but this old demo might give you some ideas too.

Hope it helps...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
pere_de_chipstic...
post Oct 10 2018, 12:35 PM
Post#13


UtterAccess Editor
Posts: 10,326
Joined: 8-November 07
From: South coast, England


Hi Massimo

I've looked over your db and made the following changes - Note that I do not have A2016 available and so some of your ribbon functionality may work in A2016 but doesn't in my (A2007) copy.

1. The ribbon name must appear in the form's ribbon property
2. I've added a reference to Microsoft Office 12 Access Database Engine Objects In the VBA window (under tools references) - yours will be a reference to a later office version
this to ensure your code compiles.
3. I've changed the ribbon schema reference to <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="onRibbonLoad1">
Again this is because your reference won't work on my PC!
4. Changed the command gobjRbn.InvalidateControl "grpEmployee" to gobjRibbon.InvalidateControl "grpEmployee"
as 'gobjRbn' was not referenced
5. I've removed the references to LoadImages, AutoScale and CenterVertically
As these are not supported in the (my) ribbon schema
6. Set the the default value of the check box to 0
7. Changed the XML line <ribbon startFromScratch="false"> to <ribbon startFromScratch="true">
This removes the default tabs and controls and leaves just the newly created ribbon controls

hth
Attached File(s)
Attached File  EmployeesDB_Updated.zip ( 73.23K )Number of downloads: 12
 

--------------------
Warm regards
Bernie
Go to the top of the page
 
mscola
post Oct 12 2018, 09:49 AM
Post#14



Posts: 25
Joined: 24-July 13



Hi Bernie

Now it works.

Thanks a lot


Massimo
Go to the top of the page
 
pere_de_chipstic...
post Oct 12 2018, 10:45 AM
Post#15


UtterAccess Editor
Posts: 10,326
Joined: 8-November 07
From: South coast, England


Glad we could help,
Good luck and continued success with your project. thumbup.gif

--------------------
Warm regards
Bernie
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th November 2018 - 12:33 PM