Call VBA Code From Right Click Menu:

mshelley1

Carbo
Local time
Today, 15:37
Joined
Feb 12, 2006
Messages
45
[RESOLVED] Call VBA Code From Right Click Menu:

Greetings:

Currently the following code is set to be called via a DblClick on a list box item; is it possible to perform this function by right clicking the item in the list box and selecting a command rather than DblClicking it?

Thanks
Mshelley


Private Sub List0_DblClick(Cancel As Integer)
On Error Resume Next
'Click Sound
PlaySound "H:\Generald\media\start.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
'Set Value for Unit, Agency and Duty Officers
Unit.Value = List0.Column(1)
AGENCY.Value = List0.Column(3)
dutyofficers.Value = List0.Column(4)
'Set date values
Month = Format(Now(), "mm")
Day = Format(Now(), "dd")
Year = Format(Now(), "yyyy")
Dispatched.Value = TIME()

If IsNull(Received) Then
Received.Value = TIME()

End If


End Sub


RESOLUTION:
See Below
Thanks "logbolt" and "Cosmos75"
 
Last edited:
Yes, this is possible but moderately difficult. Also, considerably cool.
1) You can construct a shortcut menu in code, or using the "Customize..." right-click option available on most other menus.
2) Set the "OnAction" property of a new shortcut menu item to the name of a public function in a class module. That function, of course, will have to find and reference the form on which the listbox appears in order to do the assignments as they exist in the code you supplied. More easily actually, that function could call a public function on the form in question.
3) Set the "Shortcut Menu Bar" property of the listbox control, on the the "Other" tab of the control's property sheet, to the name of your new shortcut menu.
Might present a bit of a learning curve, might not. Is possible though.
Cheers,
 
I am intrigued with your response , would you be kind enough to elaborate further as my experience dealing with menus is little.

Thank you
Mshelley1
 
Nice link.
But in addition, if you want popup menu items that run your own code, then in the "Customize" dialog, "Commands" tab, select "File" from the "Categories" list and the first command in the "Commands" list on the right is "Custom".
Drag and drop that item onto your new menu.
Right click that item and
1) Rename it
2) Click the last item in the popup "Properties"
This opens the property sheet for the commandbar control
Set the "OnAction" property to the name of public function or macro to run when the menu item is clicked.

Also, I've included an image that show where Access keeps your shortcut menus because they don't appear in the list in the Customize dialog. Also an image of the Menu Control Properties dialog, where you set the OnAction property.
 

Attachments

  • scMenuLocation.jpg
    scMenuLocation.jpg
    54.2 KB · Views: 1,564
  • scMenuControlProperties.jpg
    scMenuControlProperties.jpg
    66.8 KB · Views: 1,414
Thanks

Thank you "lagbolt" and "Cosmos75" that did the trick.

Mshelley1
 

Users who are viewing this thread

Back
Top Bottom