Answered by:
Ribbon OnLoad Event - Trying to Hide a ribbon group based on report

Question
-
I'm upgrading a MS Access 2003 application of mine to 2016 and am struggling with the ribbon on one particular point - making a group visible/invisible depending on what report is active.
My problem possibly boils down to this - can I have two ribbons (one for my main form, one for all reports) and two different OnLoad callback events for them, so that I can interact with them separately? Reports are always opened in Preview mode and I want to hide a group for all reports except one. In my XML for the Main and PrintPreview ribbons, I set separate OnLoad callbacks as seen below. For the PrintPreview ribbon, I added code to the Report_Activate events of my reports and hide the group using the getVisible callback, but I get an error message when I open one of the reports saying it can't find the OnLoad callback function.
Main ribbon XML:
<?xml version="1.0" encoding="utf-8"?> <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="onMainRibbonLoad"> <ribbon startFromScratch="true"> <tabs> <tab id="Reports" label="Reports"> <group id="Checklist" label="Checklist"> <button id="rptContestChecklist" imageMso="SetLanguage" tag="rptContestChecklist" onAction="OpenReport" size="large" supertip="Open Contest Checklist report"/> </group> <group id="ReportsGrp" label="Reports"> <button id="rptAwardWinnersReport" imageMso="ViewWebLayoutView" label="Award Winners (Website)" tag="rptAwardWinnersReport" onAction="OpenReport" size="large" supertip="Open Contest Winners for Website report"/> </group> </tab> </tabs> </ribbon> </customUI>
PrintPreview XML:
<?xml version="1.0" encoding="utf-8"?> <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="onPrintPreviewRibbonLoad"> <ribbon startFromScratch="true"> <tabs> <tab id="WF_Print_Preview" label="WF_Print_Preview"> <group idMso="GroupPrintPreviewPrintAccess"/> <group idMso="GroupZoom"/> <group id="GenerateHTML" label="Generate HTML" getVisible="GetVisibleCallback"> <button id="CreateHTML" imageMso="HyperlinkInsert" size="large" supertip="Generate HTML files of contest winners for website"/> </group> <group idMso="GroupPrintPreviewData"/> <group idMso="GroupPrintPreviewClosePreview"/> </tab> </tabs> </ribbon> </customUI>
VB code (basRibbon):
Public globalMainRibbon As IRibbonUI Public globalPrintPreviewRibbon As IRibbonUI Public globalGenHTMLVisibleTrueFalse As Boolean 'Get a global reference to the main ribbon object when the ribbon loads Public Sub onMainRibbonLoad(ByVal ribbon As IRibbonUI) Set globalMainRibbon = ribbon End Sub 'Get a global reference to the print preview ribbon object when the ribbon loads Public Sub onPrintPreviewRibbonLoad(ByVal ribbon As IRibbonUI) Set globalPrintPreviewRibbon = ribbon End Sub
VBA code (rptAwardWinnersReport):
Private Sub Report_Activate() globalGenHTMLVisibleTrueFalse = True globalPrintPreviewRibbon.Invalidate End Sub
What am I doing wrong?
Monday, July 11, 2016 11:53 PM
Answers
-
Update: I just tried this and it works:
Private Sub Report_Activate() globalGenHTMLVisibleTrueFalse = True If Not globalPrintPreviewRibbon Is Nothing Then globalPrintPreviewRibbon.Invalidate End If End Sub
This is on the code module of the report where I do want to see the group on my custom 'PrintPreview' ribbon. The code is the same on all other reports except the boolean variable is set to False.
- Proposed as answer by Edward8520Microsoft contingent staff Wednesday, July 13, 2016 3:01 AM
- Marked as answer by RosscoePColtrane Wednesday, July 13, 2016 11:46 AM
Tuesday, July 12, 2016 5:49 PM
All replies
-
Hi RosscoePColtrane,
>> get an error message when I open one of the reports saying it can't find the OnLoad callback function
Where did you put your callback? I suggest you check two points below:
- Tools->Reference->add Microsoft Office x.x Object Library
- Put your callback in Modules instead of the Form or Report Object
>> can I have two ribbons (one for my main form, one for all reports) and two different OnLoad callback events for them
In my option, there is no need to specify OnLoad Callback. You could set different Ribbons for every Form or Report by Form(Report)->Property Sheet->Other tab->Ribbon Name-> select the Ribbon for your Form or Report. You could refer the link below for more information.
# How to: Apply a Custom Ribbon to a Form or Report
https://msdn.microsoft.com/en-us/library/office/ff196428.aspx
Best Regards,
Edward
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Edward8520Microsoft contingent staff Wednesday, July 13, 2016 3:01 AM
Tuesday, July 12, 2016 5:34 AM -
Thanks for replying so quickly, Edward. Much appreciated.
I have my callbacks in modules and I do have a reference to the MS Office object library. But I did neglect to mention a pertinent item that you brought up - the form does have its Ribbon property set to my custom 'Main' ribbon and all my reports have their Ribbon property set to my custom 'PrintPreview' ribbon.
- Does that mean I don't need OnLoad callbacks for the two custom ribbons?
- If the above is true, how do I dynamically hide a group/button on the ribbon depending on what report is active?
- How do I get a reference to the active form/reports Ribbon property?
- Do I still need the getVisible callback on the group?
Sorry if this is too many questions in one post. I was quite comfortable with the old Menubar in Access 2003 but this is taking me a while to get up to speed.
Tuesday, July 12, 2016 1:30 PM -
Update: I just tried this and it works:
Private Sub Report_Activate() globalGenHTMLVisibleTrueFalse = True If Not globalPrintPreviewRibbon Is Nothing Then globalPrintPreviewRibbon.Invalidate End If End Sub
This is on the code module of the report where I do want to see the group on my custom 'PrintPreview' ribbon. The code is the same on all other reports except the boolean variable is set to False.
- Proposed as answer by Edward8520Microsoft contingent staff Wednesday, July 13, 2016 3:01 AM
- Marked as answer by RosscoePColtrane Wednesday, July 13, 2016 11:46 AM
Tuesday, July 12, 2016 5:49 PM -
Hi RosscoePColtrane,
In my option, you do not need OnLoad callbacks, dynamically show/hide a group would be achieved by Access database if you set the Ribbon property for the Form and Report. The Ribbon will change when you switch between different Form and Report after you setting Ribbon property.
It seems your original issue has been resolved, am I right? If so, I would suggest you mark the helpful reply as answer. If not, please feel free to let us know your current issue.
Best Regards,
Edward
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Wednesday, July 13, 2016 3:06 AM -
Hi Edward, I need to hide/unhide a group on my custom PrintPreview ribbon depending on which report is active; for most reports the group must be hidden but for just one it needs to be visible. With the change in the Report_Activate code above it now works perfectly. Thanks, Ross
- Edited by RosscoePColtrane Wednesday, July 13, 2016 10:35 PM
Wednesday, July 13, 2016 11:50 AM