We help IT Professionals succeed at work.

Adding Macros to the ribbon in MS Access using USysRibbons

I'm new to using xml, but not new to Access or VBA. I need to create a deployable ribbon that can be customized upon load based on the users role. I am creating this ribbon using a USysRibbons table to hold the XML code. I can add built-in controls no problem. Where I am stuck is adding controls that call saved macros or procedures. Below is code I'm testing with, but line 6 doesn't work. Any help is appreciated!

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon startFromScratch="true">
    <tabs>
      <tab id="dbChecklists" label="zChecklists" visible="true">
        <group id="dbRCL_Forms" label="Forms">
          <control idMso="Macro: macRCL_Add" label="Add" enabled="true"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

Open in new window

Comment
Watch Question

Most Valuable Expert 2012
Top Expert 2013
Commented:
Here's an example from one of my databases, of a ribbon button that adds a new client record.  You can call a procedure using the onAction.  The XML:

                    <button id="btnNewClient"
                              imageMso="QueryAppend"
                              label="Add new client"
                              size="large"
                              onAction="btnNewClient_Click"/>

Open in new window


The VBA:

Public Sub btnNewClient_Click(ctl As IRibbonControl)
    DoCmd.GoToRecord acDataForm, "frmClients", acNewRec

End Sub

Open in new window

Most Valuable Expert 2012
Top Expert 2013

Commented:
There are also third party tools available, such as Ribbon Creator, which make very short work of this.

Author

Commented:
Still no luck. I changed line 6 to the following:
          <button id="RCL_Add" label = "Add" onaction="btnAdd_RCL" enabled="true"/>

Open in new window


And I added a public procedure as you showed:
Public Sub btnAdd_RCL()
    DoCmd.OpenForm "frmRCL_Add"
End Sub

Open in new window


The XML part isn't being accepted. What am I missing? Thanks.
OK I finally got it to work. Apparently you can't use the enabled switch for a button?

          <button id="RCL_Add" label = "AddMe" onAction="macRCL_Add"  />

Open in new window

Most Valuable Expert 2012
Top Expert 2013

Commented:
Interesting!  I actually haven't tried the enabled property on a ribbon command button.  I'll check it out tomorrow... Perhaps you need a similar property such as Locked (?)

Author

Commented:
Primary failure was using the illegal switch of 'enabled="true"'.