How to reference controls on a Ribbon (1 Viewer)

cosmarchy

Registered User.
Local time
Today, 08:46
Joined
Jan 19, 2010
Messages
116
I have a ribbon with a splitButton:
Code:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnRibbonLoad" loadImage="LoadImages">
    <ribbon startFromScratch="false">
        <tabs>
            <tab id="elcdb" label="EDB">
                <group id="elcdb" label="EDB">
                    <splitButton id="MySplitButton2" size="large">
                        <button id="Button50" label="Large Button with Menu" getImage="getimage1" onAction="MyButtonCallbackOnAction200"/>
                        <menu id="Menu20" itemSize="normal">
                            <button id="Button60" label="First" getImage="getimage2" onAction="MyButtonCallbackOnAction201"/>
                            <button id="Button70" label="Second" getImage="getimage3" onAction="MyButtonCallbackOnAction202"/>
                            <button id="Button80" label="Third" getImage="getimage4" onAction="MyButtonCallbackOnAction203"/>
                        </menu>
                    </splitButton>
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

When I click on either Button60, Button70 or Button80 I'd like to set the image on Button50 to match the image on the button clicked on.

So, if I clicked on Button60, callback MyButtonCallbackOnAction201 is called and this should set the image on Button50, but the question is how? How do you reference Button50's image from a callback which has run from Button60?

If you can reference another control, it would allow you to do more than just set images as you could disable / enable buttons for example :)

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:46
Joined
Oct 29, 2018
Messages
21,473
I think you would use the id tag you assigned to the button. You also may have to use the InvalidateControl method to update the button's image.
 

cosmarchy

Registered User.
Local time
Today, 08:46
Joined
Jan 19, 2010
Messages
116
I think you would use the id tag you assigned to the button. You also may have to use the InvalidateControl method to update the button's image.

I wondered about whether that would work too, but I think I should have explained myself better :rolleyes:

I was thinking about how to reference the button via code... Since my OnRibbonLoad looks like this:
Code:
Public MyRibbon As IRibbonUI
Function onRibbonLoad(ribbon As IRibbonUI)
    On Error GoTo errorHandler
   
    Set MyRibbon = ribbon
   
    Debug.Assert False
   
errorHandler:
    Exit Function
End Function

I was expecting to be able to do something like this pseudo code from anywhere in the module:
Code:
MyRibbon.control("control50").setImage("printpreview")
MyRibbon.control("control50").invalidate

but I cannot find any functions which look like they will do this
 
Last edited:

GPGeorge

Grover Park George
Local time
Today, 08:46
Joined
Nov 25, 2004
Messages
1,873
I think you would use the id tag you assigned to the button. You also may have to use the InvalidateControl method to update the button's image.
Correct, I believe. The InvalidateControl method has the effect of forcing the ribbon to refresh itself in order to replace the now "invalid" property with whatever is now appropriate (probably not a good explanation of the actual action, but descriptive). In an Access form, it' would be similar to a "Refresh" method.

Also, investigate Callback functions.
 

cosmarchy

Registered User.
Local time
Today, 08:46
Joined
Jan 19, 2010
Messages
116
Correct, I believe. The InvalidateControl method has the effect of forcing the ribbon to refresh itself in order to replace the now "invalid" property with whatever is now appropriate (probably not a good explanation of the actual action, but descriptive). In an Access form, it' would be similar to a "Refresh" method.

Also, investigate Callback functions.
CallBack functions all tend to allow changes to the whatever control was clicked and not another one elsewhere in the ribbon - at least that I can see from the available CallBack functions I've found...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:46
Joined
Oct 29, 2018
Messages
21,473
CallBack functions all tend to allow changes to the whatever control was clicked and not another one elsewhere in the ribbon - at least that I can see from the available CallBack functions I've found...
Hi. You should be able to execute pretty much anything from a single callback. Can you post a sample db, so we can see the problem?
 

MarkK

bit cruncher
Local time
Today, 08:46
Joined
Mar 17, 2004
Messages
8,181
CallBack functions all tend to allow changes to the whatever control was clicked
Invalidate the group that contains the controls you want re-rendered, or invalidate the whole ribbon.
 

Users who are viewing this thread

Top Bottom