newbie: needhelp with custom built menu bar

G

Guest

I already know the way to create custom menu bar in Access by point to:
Tool-->Customize--> and then drag custom menu into outside.
But I wonder if there is a way to put (simple) VBA code into custom menu bar?
I mean, for example, I already have a blank custom menu bar, and then I put
some thing symbol into it, and then write some code for click event of that
symbol (ex: docmd.openform "employees"). When I click that symbol on custom
menu bar, it will open form employees for me.
many thanks
 
G

Guest

hi,
code not needed to open a form.
Tool-->Customize-->
In the catagory pane of the commmand tab, click all forms
all your forms will appear in the commands pane.
click and drag the form you want to the custom menu bar.
it will appear as a form icon. click the icon, then click
modify selection on the customize box. you have a number
of options here but click edit button image...
here you can change the default form icon to anthing you
want.
when done close the customize box.
click you new icon and the selected form will open.
you can do this with queries, tables and macros too.
 
G

Guest

Firstly, Create a new module and a new Public Function as follows:

Public Function myTest()
Msgbox "You've got a custom click thing going on here..!"

'You could of course put in DoCmd.OpenForm here...

End Function

Next, click on Tools > Customize and select the custom menu bar from the
toolbars list. Right click on the cusotm option that you want the function
to run from. Select Properties.

In the 'On Action' field, enter "=myTest()" without the quotes.

Close down the custom menu, and then try and click that button. You should
get your message box.
 
A

Albert D. Kallal

yes, in fact more often then not, my menu bars run code in the particular
form.

Lets assume we have a button on our form, and that button code prints a
invoice. Lets assume we now want to move the button code up to the menu
bar.

Here is our button code that prints the invoice:

Private Sub Command13_Click()

Dim tblgroupid As Long

tblgroupid = me.frmMainClientB.Form!ID

If me.InvoiceNumber = 0 Then
me.InvoiceNumber = nextinvoice
End If

Me.Refresh
DoCmd.OpenForm "guiInvoicePrint", , , "id = " & tblgroupid

end Sub

The above code checks for a invoice number, and if there is NOT one, then
a invoiceNum is made, saves to disk, and then prints the one reocrd.

To make the above work with a menu bar, I simply change the above code to a
PUBLIC function. Note that this can, and should remain in the in
form..as that is where it belongs. However, menu bars can call any public
function you make, be it in a form, or a standard module.

So, lets make the above into a function, we get:

Private Sub Command13_Click()

MyInvoicePrint

end Sub

Public Function MyInvoicePrint

Dim tblgroupid As Long

tblgroupid = me.frmMainClientB.Form!ID

If me.InvoiceNumber = 0 Then
me.InvoiceNumber = nextinvoice
End If

Me.Refresh
DoCmd.OpenForm "guiInvoicePrint", , , "id = " & tblgroupid

end Function

You can see that we just move the code to a public function. Our button
will still work. Now, in the menu bar, add a custom button, and in the
on-action of the menu option, simply put:

=MyInvoicePrint()

You are done.
 
G

Guest

thank all you very much.
All of them worked for me.
Now I'm leaning the ways you teached me.
Once again, thank you
 

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