Open form from Ribbon

A

Albert D. Kallal

You ribbon code can run code in a form or module.

=YourPublicFunctionName()

So, Just set the on-action to the name of your function

eg:

<button id="button1" label="Buttion1" onAction="=MyTest1()"/>

So, simply place a public function in the form called


Public MyTest1

and, you can have that function in a standard code module also....

So, if you have a bunch of form code, and want to move the code from buttons
on the form to a ribbon, simply have both your buttons on the forms, and the
ribbon code both call the same code:

Private Sub Command18_Click()

MyPrintInvoice

End Sub

And, for the button, you would go:

<button id="button1" label="Buttion1"
onAction="=MyPrintInvoice()"/>


And, then either in the forms module, or a standard public module, you go

Public Function MyPrintInvoice()

.....you code here.....

end function
 
A

Albert D. Kallal

So, lets go:


Public function OpenMyform(strF as string)

docmd.Openform strF

end if


now, to open form customers, you go:

<button id="OpenCust" label="View Customers"
onAction="=OpenMyForm('frmCustomers')"/>


Note how I did use single quotes to pass a string value...it does work...

so, now we have a general re-usable public function that allows you to build
custom ribbon buttons that opens a form of your choosing....
 
G

Guest

Perfect!

It's just what I was looking for to avoid a large number of macros.
I now have Ribbons where and when I want them. It appears that the A2003
Shortcut Menus and Toolbars cannot be created or edited in A2007. I have
posted a question on this before, but, perhaps because A2007 is till new, no
response.

Are you able to shed some light on this? i.e. Can we create shortcut menus
(Rt Click) in A2007? Can one create a custom Quick Access Toolbar or at least
disable the default toolbar.

Thanks for your help.
 
A

Albert D. Kallal

It appears that the A2003
Shortcut Menus and Toolbars cannot be created or edited in A2007. I have
posted a question on this before, but, perhaps because A2007 is till new,
no
response.

You can't change them via the ui. I am a big fan of menu bars, but I
*always* used the GUI to build those menus.

A good number of people actually used code to build those menu bars:

I don't think you can "add" new command bars, but you can certainly
manipulate existing ones via code.

The problem is that when you display a "old" menu bar it appears in the
"add-ins" tab.

So, you can for example "display" a particular menu bar (or specify it in
the forms other tab like you always did)

eg:

commandbars("name of menu bar").Visible = true

When you run the above code, the menu bar will appear, but, it appears in
the "add-ins" tab.

So, presumably, you could/would use the add-ins tab, and display your custom
ribbon items on that also (that would be a easy way to hide the rest of the
interface).

And, you can still specify a shortcut menu (right click) for a form. I not
tired adding to existing menu bars via code
but, I have to assume that shortcut menu bars can be added via code.
Are you able to shed some light on this? i.e. Can we create shortcut menus
(Rt Click) in A2007?

You should be able to, but you can' use the GUI to do this.
Can one create a custom Quick Access Toolbar or at least
disable the default toolbar.

I assume so. I know you can't turn off the office button, but you can
customize it as you please...

I not yet built something that hides the 07 interface, but hope to post a
example soon...
 
G

Guest

Thanks again for your detailed and helpful response.

I have decided that I, and my users, will live without Menu Bars and
Shortcut Menus. The new UI is just too flexible and helpful to stick to old
habits. I have created 2007 and imported all objects without the 2003 Menu
and Shortcut Bars. The Ribbon takes care of everything and all in one place,
as it was designed to do. The new advantage of running code from it provides
all I need for a friendy and intuitive UI.

I will keep an eye on this group for discussion on hiding the Quick Access
Toolbar.
This could create problems for curious users!
 

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

Similar Threads


Top