VBA & Ribbons

bg2k

New member
Local time
Today, 13:58
Joined
Apr 13, 2008
Messages
1
Hi

I have successfully created a custom ribbon in MS Access 2007 :)

Now I want to take it one step further and put buttons that run macros on it, should be simple? Well I can get macros to run from the macro feature in MS Access 2007, but I want to get macros to run from a module in VBA as this gives me greater control. Whenever I try to run them this way I get the message "Can't run the macro or callback...".

I have spent hours searching the net and so far haven't been able to work out the solution (is it even possible) any help would be appreciated!

Thanks
 
its probably a bit late now and you might have figured it out but here is what i have done to make my ribbons run vb code.

create a macro to hold all macros associated with the ribbon and call it Ribbon.

in your ribbon xml, you need onLoad="Ribbon.RunVBFunction"
( where VBFunction is the public function in a module to run the code )

create a module called basRunFunctions
( this keeps it tidy )
and place your functions in here. for example
Public Function RunVBFunction()
VBFunction
End Function

then create another module called basRibbonControls
( this will hold all code for the ribbon )

you would then add-

Public Sub VBFunction()
'Run your Code Here
End Sub

the reason i have done it this way is because the ribbon works best running a macro. a macro can run a function but not a sub and functions are limited whereas subs can do much more.
( i found functions constantly gave me errors with form items etc ).

you must remember to make functions and subs public and declare any variables. i created a modules called basPublic and declared everything in there.

my ribbon is dynamic. it has populated comboboxes that are dynamically updated and invalidated. there is a good book out now on Wiley.com called RibbonX. i learnt it in around 2 weeks. i now have dynamic callbacks that get the current username to display in a label, current outstanding tasks etc. its very good when you get into it.

regs,

Nigel
 

Users who are viewing this thread

Back
Top Bottom