How do you select a specific ribbon tab (1 Viewer)

cosmarchy

Registered User.
Local time
Today, 00:59
Joined
Jan 19, 2010
Messages
116
I have a database with two forms each one using a specific ContextTab ribbon as defined within the USysRibbons table.

The form in question is using the following ribbon XML:

Code:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" loadImage="LoadImages" onLoad="Ribbon2OnLoad">
    <ribbon startFromScratch="false">
        <contextualTabs>
            <tabSet idMso="TabSetFormReportExtensibility">
                <tab id="tabContextual2" label="My Contextual Tab 2">
                    <group id="contextualGroup" label="My Group">
                        <labelControl id="myLabels" label="Sample 2"/>
                        <button id="btnDemo" size="large" label="Demo 2"/>
                    </group>
                </tab>
            </tabSet>
        </contextualTabs>   
    </ribbon>
</customUI>

and the form has the following VBA code:
Code:
Option Compare Database
Option Explicit

Public MyRibbon As IRibbonUI

Function onRibbonLoad(ribbon As IRibbonUI)
    On Error GoTo errorHandler
    
    Set MyRibbon = ribbon
    
    'Debug.Assert False
    
errorHandler:
    Exit Function
End Function

Function Ribbon2OnLoad(ribbon As IRibbonUI)
    On Error GoTo errorHandler
    
    MyRibbon.ActivateTab "tabContextual2"
    
    'Debug.Assert False
    
errorHandler:
    Exit Function
End Function

When the database opens, there are no errors as you would expect. But, when you open the form you get the following error:
1663431992175.png


and after hitting debug, the code stops at: MyRibbon.ActivateTab "tabContextual2".

"tabContextual2" is a valid tab ID and I've even tried using the label "My Contextual Tab 2" but this does not work either.

All, I'm trying to achieve, it to activate the contextual tab when the form is active so that I don't activate the form and then have to click on the tab to use it.

Any ideas whats going on here? Thanks
 

MarkK

bit cruncher
Local time
Today, 00:59
Joined
Mar 17, 2004
Messages
8,181
In this code....
Rich (BB code):
Function Ribbon2OnLoad(ribbon As IRibbonUI)
    On Error GoTo errorHandler
    
    MyRibbon.ActivateTab "tabContextual2"
    
    'Debug.Assert False
    
errorHandler:
    Exit Function
End Function
...the IRibbonUI parameter shown in red is never assigned to the IRibbonUI variable shown in blue. As a result, you are running the .ActivateTab method of the wrong IRibbonUI object.
 

cosmarchy

Registered User.
Local time
Today, 00:59
Joined
Jan 19, 2010
Messages
116
Thanks @MarkK,

I think that may have been the issue :D
 

Users who are viewing this thread

Top Bottom