I have a custom ribbon that calls vba commands. When it does, I get the error message
Microsoft Access cannot run the macro or callback function [FUNCTION OR SUB]
where [FUNCTION OR SUB]
is the Function or Sub name I am calling.
An example of the code that generates the above message is:
Public Function OnButtonPress2(ctl As IRibbonControl)
MsgBox "OnButtonPress2"
End Function
Where OnButtonPress2
is called in the ribbon's XML file for a button as
onAction="OnButtonPress2
The above works for a macro, so it's likely not to be the ribbon's xml
======== VERSION 2 I've created a new simple test db with the XML and module shown below:
The results of each are:
Macro1 - works fine (it has a popup message)
CommandOnAction2 - msgbox "There was an error compiling this function"
OnButtonPress2 - msgbox "Microsoft Access cannot run the macro or callback function 'OnButtonPress2 '
on the line "Public gobjRibn As IRibbonUI", IRibbonUI does not autocomplete leading me to believe there is a reference that needs to be added
XML (Ribbon name is NewRibbon and is set to open on startup)
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="tab1" label="Your Custom Tab">
<group id="group1" label="Your Custom Group">
<button id="SampleButton" label="Macro1" onAction="Macro1" />
<button id="SampleButton2" label="CommandOnAction2" onAction="=CommandOnAction2()" />
<button id="SampleButton3" label="OnButtonPress2" onAction="OnButtonPress2" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
module (name is modRibbon)
Option Compare Database
Public gobjRibn As IRibbonUI
Public Function CommandOnAction2(ByVal ctl As IRibbonControl)
MsgBox "Function CommandOnAction2"
End Function
Public Sub OnButtonPress2(ByVal ctl As IRibbonControl)
MsgBox " Sub OnButtonPress2"
End Sub