Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to disable a button/item in a user created popup menu

Status
Not open for further replies.

TheFitz

Programmer
Dec 18, 2003
140
GB
Hi All,

I'm trying to work out how to disable a single item on a popup menu. Let me start from the begininning.

I've got a form with a treeview attached. When a record is selected using right-click on the menu TreeView, a popup menu appears. Depending on the state of the record on the treeview, I want to manipulate the popup menu items.

For example assume there are 4 possible child records that the parent can have (sorry, bit of a fruit theme going on!):
a) Apricots
b) Bananas
c) Crunchy Apples
d) Delicious Plums

Assuming "George" (the parent record) has already had "Delicious Plums", I either do not want to display this option or disable this option on the list.

I've spent a number of hours searcing my good friend google and the best he can come up with is:

Code:
....
'Called to disable the toolbar
Call CommandbarEnable(CommandBars("xxPopupMenu"), False, 1, 4)

and the CommandbarEnable function:

Code:
Function CommandbarEnable(Cmdbar As CommandBar, _
   CmdbarEnabled As Boolean, TopLevel As Integer, _
   Optional Sublevel As Integer)

   Dim SubCommandbar

   On Error GoTo Err_CommandBarEnable

   If Cmdbar.Visible = False Then Cmdbar.Visible = True

      If IsMissing(Sublevel) Or Sublevel = 0 Then
         Cmdbar.Controls(TopLevel).Enabled = CmdbarEnabled
      Else
         Set SubCommandbar = Cmdbar.Controls(TopLevel)
         SubCommandbar.Controls(Sublevel).Enabled = CmdbarEnabled
      End If

Exit_CommandBarEnable:
      Exit Function

Err_CommandBarEnable:
   MsgBox "Error " & CStr(Err) & " " & Err.Description & _
      " has occurred in the CommandBarEnable Function", vbOKOnly, _
      "Error Detected"
   Resume Exit_CommandBarEnable

End Function

Has anyone got any thoughs on this??

Many thanks in advance for any time you spend on this,

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
Looks like I found it myself, easy when you know how!!

Code:
CommandBars("xxPopupMenu").Controls("Add Delicious Plum Record").Enabled = False

One line!! That was it, no other code!!

Don't I feel silly!!!

Thanks anyway for anyone who had a look.

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top