Callback problems with Ribbon

G

gthelin

I am trying to get callbacks to work with ribbon. Nothing I try seems to
work. I get the error message "Microsoft Office Access can't run the macro
or callback function 'onOpenForm'. I have added the Microsoft Office Objects
12.0 Library but it still does not work. I tried creating a small db and did
get it to work there. But in the db that I need it I just get the error
message.

Here is the XML:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false"> <tabs>
<tab id="tabMyStuff" label="MyStuff">
<group id="grpForms" label="Forms">
<button id="cmdOrders" label="Orders" onAction="onOpenForm"
tag="Orders" size="large"/>
<button id="cmdVendors" label="Orders2"
onAction="Ribbons.onOpenForm" tag="Orders" size="large"/>
</group>
<group id="grpReports" label="Reports">
<button id="cmdReports" label="Quote"
onAction="Ribbon.OpenfrmInvoice" size="large"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

Here is the call back function (it is in a module called Ribbons).

Public Sub onOpenForm(ctl As IRibbonControl)
DoCmd.OpenForm ctl.Tag
End Sub

I tried to ref the callback in XML with the module name ribbons and with out
it. Nothing seems to work. Any thoughts?
 
A

Albert D. Kallal

The "on action" command does not pass the ribbon object, but just runs any
standard vba "PUBLIC" function you have..

So you On Action should be:

<button id="cmdOrders" label="Orders" onAction="=onOpenForm()"


note the additon of the = and also the ()

(the ribbion is quite picky in this regards).

So, now in a standard public module (or the the current forms module if you
want)
you then go:

Public Function onOpenform

end function

Of couse in your example you trying to use the "tag", and you don't need to,
just pass the value as a string right from the buttion like:

eg:

<button id="cmdOrders" label="Orders" onAction="=onOpenForm('Orders')"

In the above, we are passing 'Orders' to our routine, so:

Now, we would modify our code to :

Public Function onOpenform(strForm as string)

docmd.OpenForm strForm

end function


So, don't bother with the tag idea, just pass whatever form to that function
as string like above.

You can also use the same idea for reports....
 
G

gthelin

Thanks for the help. I tried the code but it did not work in my database. I
created a new database and it did work there. Can you think what there might
be in my database that is preventing it from working?
 
A

Albert D. Kallal

gthelin said:
Thanks for the help. I tried the code but it did not work in my database.
I
created a new database and it did work there. Can you think what there
might
be in my database that is preventing it from working?

Well, I assume you done a debug-compile.

and other VBA code runs just fine in the application?

I suppose you could create a blank new database and then import everything
from the old one.

There has to be something really silly here that is not allowing the code to
work.

Note that the code called needs to be a FUNCTION, and MUST be public.
That public function the onAction calls can either be in the forms code
module, or a standard code module.

Do remember that each change you make to the ribbon requires you to exit,
and re-enter the application

(because of this, I put the compact and repair button on the "qat" (quick
access tool bar).

Now, when I change the ribbon...I just whack the compact/repair button
(think of that compact/repair button as a ribbon "compile" button....saves
you the time
having to exit and then re-enter the application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top