Ribbon won't execute VB functions

smlrwd

New member
Local time
Today, 06:33
Joined
Oct 7, 2010
Messages
8
Hi All,

I'm making a custom ribbon for Access but when I start Access I get;

"...can't run the macro or callback function 'CallbackOnLoad'"
"...can't run the macro or callback function 'GetLink'"
"...can't run the macro or callback function 'GetText'"

Also, none of the buttons on the Ribbon work or have their updated names. I get errors such as;

"...can't run the macro or callback function 'PublicAction'"

Is there a reason nothing would be working, except for the Database Administration Tab? I can Compact and Repair Database and make a ACCDE, but nothing else on the ribbon seems to be working.

I think there is something simple I am missing, but I just can't see it and want to see if anyone here can help me out.

Here is the XML I'm using, followed by a sample of the VB.

Code:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="CallbackOnLoad">
<commands>
<command idMso="FileNewDatabase" enabled="false"/>
<command idMso="FileCloseDatabase" enabled="false"/>
<command idMso="ApplicationOptionDialog" enabled="false"/>
<command idMso="FileOpenDatabase" enabled="false"/>
<command idMso="FileSaveAs" enabled="false"/>
<command idMso="FileSave" enabled="true"/>
<commands>
<ribbon startFromScratch="true">
<officeMenu>
<button idMso="ApplicationOptionsDialog" visible="false"/>
<splitButton idMso="FileSaveAsMenuAccess" visible="false"/>
<button idMso="FileSaveAs" visible="false"/>
<control idMso="Undo"/>
<control idMso="Redo"/>
<control idMso="Cut"/>
<control idMso="Copy"/>
<control idMso="Paste"/>
<button idMso=FileSave" visible="true"/>
<button idMso="FileCloseDatabase" visible="false"/>
<button idMso="FileNewDatabase" visible="false"/>
<button idMso="FileOpenDatabase" visible="false"/>
</officeMenu>
<tabs>
<tab idMso="TabCreate" visible="false"/>
<tab id="dbCustomTab" label="Main Menu" visible="true">
<group id="dbCustomGroup1" label="Device Management">
<separator id="separator12"/>
<button id="OpenSwitch" screentip="Open Switch Form" label="Switches"
imageMso="DiagramRadialInsertClassic" size="large" on Action="PublicAction"/>
<separator id="separator1" visible="false"/>
<button id="OpenVLANs" screentip="Open VLAN Form" label="VLANs"
imageMso="FileServerTransferDatabase" size="large" onAction="PublicAction"/>
<separator id="separator2" visible="false"/>
<box id="box1" boxStyle="horizontal">
<labelControl id="myLabel2" label=" IP or computer"/>
</box>
<box id="box2" boxStyle="horizontal">
<editBox id="PingBox" onChange="MyEditBoxCallbackOnChange" sizeString="wwwwwwwwww"/>
</box>
<box id="box16" boxStyle="horizontal">
<labelControl id="myLabel9" label=" "/>
<button id="Ping" screentip="Ping and switch or computer on the network" label="Ping"
imageMso="DiagramTargetInsertClassic" onAction="PublicAction"/>
</box>
<separator id="separator6"/>
<box id="box11" boxStyle="vertical">
</box>
<box id="box3" boxStyle="horizontal">
<labelControl id="myLabel4" label=" Device IP"/>
</box>
<box id="box4" boxStyle="horizontal">
<labelControl id="IPLabel" label="xxx.xxx."/>
<editBox id="SSHBox" onChange="MyEditBoxCallbackOnChange" sizeString="wwwww"/>
</box>
<box id="box12" boxStyle="horizontal">
<labelControl id="myLabel8" label=" "/>
<button id="SSH" screentip="SSH to any device on the network" label="SSH"
<imageMso="ServerConnection" onAction="PublicAction"/>
</box>
<separator id="separator13"/>
</group>
<group id="dbCustomGroup9" label="Custom Links">
<separator id="separator26"/>
<box id="box5" boxStyle="vertical">
<button id="Link1" imageMso="PivotGroupItems" getLabel="GetLink" onAction="MenuAction"/>
<button id="Link2" imageMso="PivotGroupItems" getLabel="GetLink" onAction="MenuAction"/>
<button id="Link3" imageMso="PivotGroupItems" getLabel="GetLink" onAction="MenuAction"/>
</box>
<separator id="separator7"/>
<box id="box6" boxStyle="vertical">
<button id="Link4" imageMso="PivotGroupItems" getLabel="GetLink" onAction="MenuAction"/>
<button id="Link5" imageMso="PivotGroupItems" getLabel="GetLink" onAction="MenuAction"/>
<button id="Link6" imageMso="PivotGroupItems" getLabel="GetLink" onAction="MenuAction"/>
</box>
<separator id="separator8"/>
<box id="box7" boxStyle="vertical">
<button id="Link7" imageMso="PivotGroupItems" getLabel="GetLink" onAction="MenuAction"/>
<button id="Link8" imageMso="PivotGroupItems" getLabel="GetLink" onAction="MenuAction"/>
<button id="Link9" imageMso="PivotGroupItems" getLabel="GetLink" onAction="MenuAction"/>
</box>
<separator id="separator25"/>
</group>
<group id=dbCustomGroup4" label="Search">
<separator id="separator14"/>
<box id="box8" boxStyle="horizontal">
<labelControl id="SearchLbl" label=" Keyword or Doc Type"/>
</box>
<box id="box9" boxStyle="horizontal">
<editBox id="MyEditBox" onChange="MyEditBoxCallbackOnChange" sizeString="wwwwwwwwwww"/>
</box>
<button id="Search" screentip="Search the Drive" label="Files"
imageMso="FileOpen" onAction="PublicAction"/>
<separator id="separator28"/>
<box id="box13" boxStyle="horizontal">
<labelControl id="NumLbl" label=" Phone Numbers"/>
</box>
<box id="box10" boxStyle="horizontal">
<editBox id=PhoneList" onChange="MyEditBoxCallbackOnChange" sizeString="wwwwwwwwwww"/>
</box>
<box id="box14" boxStyle="horizontal">
<button id="SearchPhone" screentip="Search for phone number" label="Numbers"
imageMso="AddressBook" onAction="PublicAction"/>
</box>
<separator id="separator15"/>
<box id="box25" boxStyle="vertical">
</box>
<box id="box24" boxStyle="horizontal">
<labelControl id="myLabel10" label=" Building #"/>
</box>
<box id="box23" boxStyle="horizontal">
<editBox id="BuildingBox" onChange="MyEditBoxCallbackOnChange" sizeString="wwwwwww"/>
</box>
<box id="box26" boxStyle="horizontal">
button id="Blg" screentip="Search for switch building" label="Switches"
imageMso="DatabaseRelationships" onAction="PublicAction"/>
</box>
<separator id="separator33"/>
</group>
<group id="dbCustomGroup8" label="Current User">
<separator id="separator23"/>
<box id="box20" boxStyle="horizontal">
<labelControl id="UserMark" label=" "/>
</box>
<box id="box21" boxStyle="horizontal">
editBox id="CurrentUser" enabled="false" getText="GetText" sizeString="wwwwwwwwwwwwwww"/>
</box>
<box id="box22" boxStyle="horizontal">
<button id="ChangeUser" screentip="Change user currently signed in" label="Change User"
imageMso="DatabasePermissionsMenu" onAction="PublicAction"/>
</box>
<separator id="separator24"/>
</group>
</tab>
<tab id="dbCustomTab4" label="Inventory" visible="true">
<group id="dbCustomGroup2" label="Inventory">
<button id="Computers" screentip="Open Computers Form" label="Computers"
imageMso="OutlookTaskCreate" size="large" onAction="PublicAction"/>
<button id="Switches" screentip="Open Switches Form" label="Switches"
imageMso="CreateReport" size="large" onAction="PublicAction"/>
</group>
</tab>
<tab id="CustomTab2" label="Database Administration" visible="true">
<group id="dbCustomGroup7" label="Maintenance">
<separator id="separator18"/>
<control idMso="FileCompactAndRepairDatabase" size="large" enabled="true"/>
<separator id="separator16"/>
<button id="BackupDB" screentip="Backup Database" label="Backup Database"
imageMso="FileBackupDatabase" size="large" onAction="PublicAction"/>
<separator id="separator17"/>
<control idMso="DatabaseMakeMdeFile" size="large" enabled="true"/>
<separator id="separator19"/>
</group>
<group id="dbCustomGroup5" label="Settings">
<button id="OpenDB" screentip="Open Database Administration Form"
imageMso="TableSharePointListsModifyColumnsAndSettings" size="large" onAction="PublicAction"/>
</group>
</tab>
<tab id="dbCustomTab3" label="Help" visible="true">
<group id="dbCustomGroup6" label="Help">
<separator id="separator20"/>
<button id="HelpGuide" screentip="Open Help Guide" label="Help Guide"
imageMso="Help" size="large" onAction="PublicAction"/>
<separator id="separator21"/>
<button id="About" screentip="Database Information" label="About"
imageMso="MacroSecurity" size="large" onAction="PublicAction"/>
<separator id="separator22"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

Code:
Option Compare Database
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds as Long)
Public strPing, strSSH, strTxt, strPhone, strBlg As String
Public gobjRibbon As IRobbonUI
 
Public Sub PublicAction (control As IRibbonControl)
On Error GoTo ribbonerr
Select Case control.ID
 
Case "helpguide": Application.FollowHyperlink _
     DBPath & "Help Guide.pdf"
Case "search":
     If IsNull (strTxt) or strTxt = "" Then
     MsgBox "Your search cannot be blank.", vbOKOnly, "Enter Item"
     Exit Sub
     End If
 
Forms!welcomefrm!SearchVar = strTxt
DoCmd.OpenForm "searchfrm", acNormal, , , , acWindowNormal
Case "Computers": DoCmd.OpenForm "computersfrm", acNormal, , , , acWindownNormal

If anything else is needed let me know and I will try and get it for you. Thanks.
 
Hi there, welcome to the forum.
Are you using a USysRibbons table?
I've had the best success working with ribbons to add the xml in very small chunks, make sure it works, and then add more chunks. I find if you throw a lot of xml at it and if fails it's very difficult to the determine where the problem is. You're missing double quotes, for instance, on line 20 of the xml you posted, which probably isn't THE problem, but stuff like that kills the whole ribbon.
As far as "can't run the macro or callback function 'CallbackOnLoad'" is concerned, do you have a function called "CallbackOnLoad" in a standard module of your database? You haven't specifically said that you do.
Cheers,
 
Thanks for the reply. Yes, I'm using the USysRibbons table. I'll take out the XML code and put it back one button or tab at a time. Hopefully that will help narrow things down a bit.

As for the double quotes, I couldn't copy-paste so I had to type it all out and missed them. It's there in the file. Thanks for noticing though, stuff like that can be a pain.

Here is the code for CallbackOnLoad, it's pretty basic. Any reason it wouldn't be working?

Code:
Sub CallbackOnLoad (ribbon As IRibbonUI)
      '  Cache a copy of RibbonUI
     Set gobjRibbon = ribbon
 
End Sub
 
To get more informative error messages try this ...
Go to OfficeButton->Access Options->Advanced->General and make sure that the "Show add-in user interface errors" checkbox is checked. Re-open your database. Now you should get more useful error messages that give you the line number, position, and description of the errors encountered in the XML.
Cheers,
 
Ok, I did what you suggested and I get the same results. I think I have stared at this for so long I can't see clearly any more. Can anyone help me out with this? This is what i choppped the code down to.

I get the error:

"... can't run the macro or callback funtion 'CallbackOnLoad'.
Make sure the macro or function exists and takes the correct parameters."

I also have to click this error 3 times, if it helps. That seems odd to me.

XML
Code:
<customUI xmlns=[URL]http://schemas.microsoft.com/office/2006/01/customui[/URL] onLoad="CallbackOnLoad">
<ribbon startFromScratch="true">
</ribbon>
</customUI>

VBA
Code:
Option Compare Database
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public strPing, strSSH, strTxt, strPhone, strBlg As String
Public gobjRibbon As IRibbonUI
 
Sub CallbackOnLoad (ribbon As IRibbonUI)
     Set gobjRibbon = ribbon
 
End Sub
 
Maybe post the db. I don't see why that would fail.
 
I have no idea what happened. I took out the tables so that I could completely lock down the original database while still being able to update the data tables I have kept seperately. (Doing something to sidetrack me while still technically progressing with the database, even though it didn't work)

But once I linked the two together and put back the original XML file and VBA scripts everything worked.

Thanks for the help.
 
You probably just needed to Compile & Repair. It's needed for refreshing the ribbon object and getting rid of errors.
 
I have the same problem, but redoing the links has not helped. I have shrunk the file down to nothing but the ribbon and still get the error.
 

Attachments

hi and welcome to the forum

IRibbonUI is a class provided by the Office object model, so in a code window, go to Tools->References and find the Microsoft Office XX.0 Object Library, and check it in the list.

You should also go to Tools->Options->Editor Tab->Code Settings Section, and check the "Require Variable Declaration" option. When set, the Access compiler is a little more picky and finds more errors in your code.

After that, your third button works, except your IF block expression is never true, so it succeeds silently and your msgbox never displays. For testing, put a MsgBox outside the If block.

Hope this helps,
 
This is not an answer to the asker's question, but because I found this thread when I was searching for an answer to my question, I thought I should post the answer I found.

If you happen to be using a function instead of a sub, you must label it with an equals sign at the beginning and open and close parentheses at the end, like this: onAction="=OpenManagement()". I had not included those and I got the error message that the asker got.
 

Users who are viewing this thread

Back
Top Bottom