471,319 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Mouse and ShortCut Menu Bar to execute my code

Hi

I am using the Shortcut Menu Bar property of a control to specify a
Custom popupmenu that displays when the right-click of the mouse is
used.

Can I place some kind of command in this Custom Right-Click Mouse
Menu, that can be selected by the user, and executes a procedure
containing my code???

ThankYou
Greg

Feb 15 '07 #1
2 4613
I would say that 90% of my custom menu bars call, and run my VBA code.

All you need to do is make the code (a function) public, and then simply
place the function name in the buttons on-action event code.

Further, likely often you will have specific code to a particular form, and
once again, you simply declare those functions (in that form) as public.

The syntax to call the code then is:

=YourFunctionName()

You place the above in the on-action setting of the menu.

Often, (if not most of the time), you code you call will need to pick up
some information about he current screen etc. So, my code most of the time
starts out, and grabs the current screen name. I use:

Public Function AskInvoicePrint()

Dim tblgroupid As Long
Dim frmActive As Form

Set frmActive = Screen.ActiveForm

tblgroupid = frmActive.frmMainClientB.Form!ID

If frmActive.InvoiceNumber = 0 Then
frmActive.InvoiceNumber = nextinvoice
frmActive.Refresh
End If

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

End Function

The above is code that the invoice print button runs. note how I right away
pick up the active form. After that, I can easily ref the forms object as if
the code was running much like the code would if put behind a button on the
form. In the above example, I also check if a invoice number has been
generated before printing. And, the Refresh forces a disk write if in fact I
do change the invoice number. And, in addition the above clip also passes
the currently selected sub-form item that the invoice print form needs.

Also, if the code you write is for the particular form, then as mentioned,
you can simply place the code into the forms module code. There is no need
to pick up the active screen...and you can use me. as you
always used.

If you want to see some sample menu bars, and why I use them, you can read
the following:

http://www.members.shaw.ca/AlbertKal...erFriendly.htm
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com


Feb 15 '07 #2
Great advice Albert!
Thanks for going the extra yard, you saved us future questions.

Greg

Feb 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Lex | last post: by
3 posts views Thread by Terry Bell | last post: by
4 posts views Thread by Salad | last post: by
reply views Thread by cefrancke | last post: by
reply views Thread by Marcel | last post: by
4 posts views Thread by I_AM_DON_AND_YOU? | last post: by
2 posts views Thread by Jorgen Bodde | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.