Can you remove groups from PrintPreview ribbon? (1 Viewer)

David Anderson

Registered User.
Local time
Today, 09:29
Joined
Nov 18, 2007
Messages
84
I have created a simple accdb database in Access 365. Its only purpose is to print labels for selected names and addresses. My objective is to create a very simple interface that hides everything that is irrelevant. With the help of https://support.microsoft.com/en-us/office/create-a-custom-ribbon-in-access, and other threads on this forum, I created my first custom UI earlier today.

My current XML is as follows, but the TabPrintPreviewAccess tab contains far too many groups for my needs. I just want to have the Print group and the Close Print Preview group. What is the simplest way to achieve this?

XML:
<?xml version="1.0" encoding="UTF-8"?>
<customUI
xmlns="http://schemas.microsoft.com/office/2009/07/customui">
  <ribbon startFromScratch="true">
    <tabs>
    <tab idMso="TabCreate" visible="false"/>
    <tab idMso="TabPrintPreviewAccess" visible="true"/>
    </tabs>
  </ribbon>
</customUI>
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:29
Joined
Oct 29, 2018
Messages
21,473
If you want a true custom ribbon, try not to use idMSo at the tab level. Add a blank tab and then add buttons using idMso.
 

David Anderson

Registered User.
Local time
Today, 09:29
Joined
Nov 18, 2007
Messages
84
Where do I find all the required settings for the Print and Close Print Preview buttons?

The id, imageMso, and onAction settings appear to be the key items.
 

tvanstiphout

Active member
Local time
Today, 01:29
Joined
Jan 22, 2016
Messages
222
I use this in a custom ribbon:
<group id="gReportOptions" label="Report Options" getVisible="gReportOptions_GetVisible">
<button idMso="PrintDialogAccess" size="large"/>
<button idMso="FilePrintQuick" size="large"/>
<button idMso="FileSendAsAttachment" size="large"/>
<button idMso="PublishToPdfOrEdoc" size="large"/>
<button idMso="PrintPreviewClose" size="large"/>
</group>

To turn the group on or off:
Sub gReportOptions_GetVisible(ByVal control As IRibbonControl, ByRef Visible As Variant)
Visible = (Reports.count > 0)
End Sub

In each report's Activate and Deactivate event:
Ribbon_ShowReportsGroup True
Ribbon_ShowReportsGroup False

Public Sub Ribbon_ShowReportsGroup(ByVal Show As Boolean)
m_Ribbon.InvalidateControl "gReportOptions"
'After InvalidateControl, the group control will call gReportOptions_GetVisible.
End Sub

m_Ribbon gets saved in ribbonLoaded, which is specified on line 1 of the XML:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="ribbonLoaded"

Private m_Ribbon As Office.IRibbonUI 'Requires reference to Microsoft Office [version] Object Library (mso.dll).
Public Sub ribbonLoaded(ByVal ribbonUI As Office.IRibbonUI)
Set m_Ribbon = ribbonUI
End Sub
 

David Anderson

Registered User.
Local time
Today, 09:29
Joined
Nov 18, 2007
Messages
84
I had already managed to track down the required idMso for Print and Close Preview after making my last post, but you have provided answers to the two issues I had found with my solution. The default icon size was too small and the Print group was still showing after I had closed a print preview.

The size="large" settings have now been added and I will now try to implement your solution for controlling the group visibility. Thanks for your help on this :)
 

David Anderson

Registered User.
Local time
Today, 09:29
Joined
Nov 18, 2007
Messages
84
I've done my best to follow your instructions (including a reference to Microsoft Office 16.0 Object Library), but I'm getting the following errors as soon as I open the database:
MyDatabase cannot run the macro or callback function 'ribbonLoaded'.
MyDatabase cannot run the macro or callback function 'gReportOptions_GetVisible'.

I've probably made a stupid mistake. Can you spot anything wrong?

XML:
<?xml version="1.0" encoding="UTF-8"?>
<customUI
xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="ribbonLoaded">
  <ribbon startFromScratch="true">
    <tabs>
    <tab idMso="TabCreate" visible="false"/>
    <tab idMso="TabPrintPreviewAccess" visible="true"/>
     <tab id="MyTab" label="MyTab" visible="true">
       <group id="gReportOptions" label=" " getVisible="gReportOptions_GetVisible">         
          <button idMso="PrintDialogAccess"  size="large"/>       
          <button idMso="PrintPreviewClose"  size="large"/>         
       </group>
    </tab>
    </tabs>
  </ribbon>
</customUI>

Code:
Option Compare Database
Option Explicit

Private m_Ribbon As Office.IRibbonUI 'Requires reference to Microsoft Office [version] Object Library (mso.dll).

Sub gReportOptions_GetVisible(ByVal control As IRibbonControl, ByRef Visible As Variant)
    Visible = (Reports.Count > 0)
End Sub

Private Sub Report_Activate()
    Ribbon_ShowReportsGroup True
End Sub

Private Sub Report_Deactivate()
    Ribbon_ShowReportsGroup False
End Sub

Public Sub Ribbon_ShowReportsGroup(ByVal Show As Boolean)
    m_Ribbon.InvalidateControl "gReportOptions"
    'After InvalidateControl, the group control will call gReportOptions_GetVisible.
End Sub

Public Sub ribbonLoaded(ByVal ribbonUI As Office.IRibbonUI)
    Set m_Ribbon = ribbonUI
End Sub
 

tvanstiphout

Active member
Local time
Today, 01:29
Joined
Jan 22, 2016
Messages
222
This goes in your report:

Private Sub Report_Activate()
Ribbon_ShowReportsGroup True
End Sub

Private Sub Report_Deactivate()
Ribbon_ShowReportsGroup False
End Sub

The rest in a Standard Module.
 

David Anderson

Registered User.
Local time
Today, 09:29
Joined
Nov 18, 2007
Messages
84
I'm still experimenting with my new interface and have added another tab, unrelated to label printing. This new tab (MyTab1) is on the far left of the ribbon and is selected by default when the database is opened. When I open a print preview I want the original print-related tab (now called MyTab2) to be selected, but this doesn't happen. How do I fix that?

So far, I have been picking up hints on how to create a custom UI from a variety of places, but none of them provide a comprehensive overview of the subject, together with a list of all available settings. Does such a source exist?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:29
Joined
Oct 29, 2018
Messages
21,473
So far, I have been picking up hints on how to create a custom UI from a variety of places, but none of them provide a comprehensive overview of the subject, together with a list of all available settings. Does such a source exist?
Have you seen this one?
 

David Anderson

Registered User.
Local time
Today, 09:29
Joined
Nov 18, 2007
Messages
84
Have you seen this one?
Yes, I stumbled across that one yesterday. It looks like an excellent resource. Chrome refused to download any of the sample databases without explaining why, but Edge gave me security warnings plus an option to download them anyway.

However, I was wondering if there were other good websites on this subject I'd not yet found. I'm surprised at the apparent lack of something like this from Microsoft itself.
 
Last edited:

Users who are viewing this thread

Top Bottom