Custom ribbon action button not working with vba (1 Viewer)

sashapixie

Registered User.
Local time
Today, 15:13
Joined
Sep 30, 2015
Messages
27
Hi There

I am new to XML and have created a custom ribbon with an action button as a test before I create my own specific tabs and buttons, using the XML below:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="MyTab1" label="My Tab 1">
<group id="MyGroup1" label="My Group">
<button id="MijnButton1" size="large" label="Print Large"
imageMso="PrintDialogAccess" onAction="MyCallBackOnAction"/>
</group>
</tab>
<tab id="MyTab2" label="My Tab 2"/>
<tab id="MyTab3" label="My Tab 3"/>
</tabs>
</ribbon>
</customUI>

I have the vba in a module to create a message box, the code is below:

[FONT=Calibri,Bold][FONT=Calibri,Bold][FONT=Calibri,Bold]
Public Sub MyCallBackOnAction(
[/FONT]​
[/FONT]​
[/FONT]control As IRibbonControl[FONT=Calibri,Bold][FONT=Calibri,Bold][FONT=Calibri,Bold])

MsgBox "Hello World", vbExclamation
End Sub
[/FONT][/FONT][/FONT]
However when I click on my button in my ribbon I get the following error

Priddy cannot run the macro or callback function "MyCallBackOnAction".
Makes sure the macro or function exists and takes the correct parameters.

(Priddy is the name of my database)

As this is my first attempt I have no idea why this does not work.

Any help is appreciated.
 

Pyro

Too busy to comment
Local time
Tomorrow, 00:13
Joined
Apr 2, 2009
Messages
126
You need to create a public object variable that will point to your ribbon

Code:
Public IRibbonControl As IRibbonUI

Then load it in at start up

Code:
Public Sub OnRibbonLoad(objRibbon As IRibbonUI)
On Error GoTo Err_OnRibbonLoad

Set IRibbonControl = objRibbon

Exit_OnRibbonLoad:
    Exit Sub
    
Err_OnRibbonLoad:
    MsgBox Err.Description
    Resume Exit_OnRibbonLoad

End Sub

See example attached. Note slightly altered XML.
 

Attachments

  • Ribbon Test.accdb
    444 KB · Views: 336

Ari

Registered User.
Local time
Today, 07:13
Joined
Oct 22, 2011
Messages
139
Sashapixie, enable reference MICROSOFT OFFICE 14.0 OBJECT LIBRARY

14.0 > Access 2010
15.0 > Access 2013
16.0 > Access 2016

IRibbonControl is a class this reference.
 

sashapixie

Registered User.
Local time
Today, 15:13
Joined
Sep 30, 2015
Messages
27
Thank you for your help, I enabled the reference and this fixed my issue :)
 

Users who are viewing this thread

Top Bottom