Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax for calling a function via a Ribbon?

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I want to place a button on a custom ribbon but can not figure out the syntax. When the user clicks the button, I want it to call a function with 2 arguments. This is how its called via a menubar in Access 2003:

=MyFunction("arg1","arg2")

What's the syntax for a ribbon? This is what I have so far:
Code:
<customUI xmlns="[URL unfurl="true"]http://schemas.microsoft.com/office/2006/01/customui">[/URL]
  <ribbon startFromScratch="false">
    <tabs>
      <tab idMso="TabCreate" visible="false" />
      <tab id="dbCustomTab" label="My Custom Tab" visible="true">
        <group id="dbCustomGroup" label="My Group 1">
          <button id="id"  label="phone book" onAction="MyFunction(""MyForm"",""Hide"")" />
          
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>
 
It appears that the onAction callback signature should look like this:

function MyFunction (ctl as IRibbonControl)
...
end function

This will not work for me without a lot of work. Is there another way to call a function rather than using onAction?
 
Because I haven't received a response to my post and after more research, I don't think there is a built-in way to do what I want.

I'm trying to change my menubars and command bars (built in Access 2000 and 2003) to the Ribbon format. I know that Access 2007 will display them under the Add-Ins tab. But it's difficult to modify them. The problem is that my menubar items call functions located in my library database. And I have about dozen systems that are referencing the library. So I can't just change my library routines to handle the callback signature without affecting the other systems (which have not yet been upgraded).

To solve the problem, I set the tag property equal to the procedure I want to call. The onAction callback routine will then use the Eval method to call the library routine.
It works like this:
Code:
<customUI...
   <button id="id"  
           label="OpenMyForm" 
           onAction="CallLibraryRoutine"
           tag="MyFunction('MyForm','Hide')" />
    ...
</customUI>
The onAction callback routine will look like this:
Code:
Sub CallLibraryRoutine(ctlRibbon As IRibbonControl)

    Eval (ctlRibbon.Tag)
    
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top