Processing options on a popup menu

stevievee

Registered User.
Local time
Today, 17:39
Joined
Jan 23, 2003
Messages
19
Hi,

I have created a popup menu programatically, so that the user can take options in a tree view by right-clicking. My popup menu is created using the commandbar object type, and is called cmdPopUpMenu.

How do I process the option taken? I have added options such as Edit, Delete etc., but I don't know how I detect when the option is clicked.

I thought I might be able to add a cmdPopUpMenu_Click() event, but I was wrong!

Thanks in advance.
 
Save the popup value to you subject form and act on it accordingly.
 
But what value do I save?

At the moment, each option runs a function called popupClick()
In this function, I look at the commandbar properties to see what was pressed. However, as soon as the function is called, it brings up an error "400" with no explanation.
 
Can you post a example of your forms, with appropriate sample table data and any queries involved?
 
This is in the Form Initialise event...

'Create Pop Up Menu...
Set mnuPopup = CommandBars.Add(TreeMenu, msoBarPopup, , True)

Set cmdCtl = mnuPopup.Controls.Add
cmdCtl.Caption = "Edit"
cmdCtl.OnAction = "popOpt"
cmdCtl.Tag = cEDIT

Set cmdCtl = mnuPopup.Controls.Add
cmdCtl.Caption = "Add Child"
cmdCtl.OnAction = "popOpt"
cmdCtl.Tag = cADDCHILD

Set cmdCtl = mnuPopup.Controls.Add
cmdCtl.Caption = "Add Resource"
cmdCtl.OnAction = "popOpt"
cmdCtl.Tag = cADDRESOURCE

Set cmdCtl = mnuPopup.Controls.Add
cmdCtl.Caption = "Delete"
cmdCtl.OnAction = "popOpt"
cmdCtl.Tag = cDELETE

This is the code that reacts to the click of an option...

Public Sub popOpt()

Select Case CommandBars.ActionControl.Tag

Case CStr(cEDIT)
frmTree!CmdEdit_Click

Case CStr(cDELETE)
frmTree!cmdDelete_Click

Case CStr(cADDCHILD)
frmTree!CmdAddChild_Click

Case CStr(cADDRESOURCE)
frmTree!cmdAddResource_Click

End Select

End Sub

PopOpt is triggered, but the message "400" appears before any code is executed.
 
I checked by Litwin, et al's Access 2002 ( & 97) Developer's Handbook, Desktop Edition (published by Sybex). It has popup menu and menu building examples of the accompanying CD, but I could get any to work on my PC.

I'd email that email database (from Litwin) or code, but that would violate the license for the book's CD. So I won't. They want to sell books.

I not smart enough to find your error. I suggest that you checkout the above reference for your error.

I do offer the following regarding your code: It builds the mneu ok, but it's permanently displayed, not a popup which is toggled. Plus the capition of the buttons are displayed. The buttons should refer to a macro which executes a function, not a form button.

I don't think you can refer to a form button from a menu.

I presume that you've used the Access debugger to single step though the code to find the instruction causing the error.

Maybe I've given you a little food for thought. Darn little probably.

The older I get, the more behind I get.
 
I've got a little further with this. The code as it stands is not too bad.

It does work as a popup, the msoBarPopup parameter takes care of this.

The function it calls (popOpt in my case) must be in a separate module, not in the Form module. This stops the error 400 occuring.

I'm now trying to call the Command_Click events which I'm failing with at the moment, because now I am outside of the Form Module. I'm guessing that i need to make the events public, they default to private. I'll try it and see what happens.

...It worked. At last, I can continue!

Thanks, everyone. :D
 
Last edited:

Users who are viewing this thread

Back
Top Bottom