popup/shortcut menu question

M

Mark Andrews

Using Access 2003 (access 2000 format):

I have created a shortcut menu to popup when the user right clicks on a
control. It works fine. Here's a good link for anyone interested in
getting started with menus:
http://www.jamiessoftware.tk/articles/menubars.html

Questions:
How do I make a menu item have a check mark?

How do I disable/enable a menu item?

Thanks in advance,
Mark
 
D

Dale Fye

1. Not sure how to change it to a checkmark. In Excel, the commanbar
buttons have a State property with is either msoButtonUp or msoButtonDown,
but I have not found a similar property in Access


2. I use code to create my menubars. Takes a little more work the first
time, but is way easier to work with in the long run. An example is my Form
menu, which gives me Close and Quit options. I generally hide the Close
option except for me (on the main form) but on forms that get opened
programmatically, I'll hide the quit option.

Public Sub FormMenu()

Dim cbr As Object
Dim cbrButton As Object

DeleteCmdBar ("MyFormMenu")
On Error GoTo FormMenuError

DoCmd.Hourglass True

Set cbr = CommandBars.Add("MyFormMenu", BarPopup, , True)

With cbr

Set cbrButton = cbr.Controls.Add(ControlButton, , , , True)
With cbrButton
.Caption = "&Close"
.Tag = "Close"
.OnAction = "=fnCloseForm()"
End With

Set cbrButton = cbr.Controls.Add(ControlButton, , , , True)
With cbrButton
.Caption = "&Quit"
.Tag = "Quit"
.OnAction = "=fnQuit()"
End With

End With

DoCmd.Hourglass False
Exit Sub
FormMenuError:
MsgBox "ReportMenu error" & vbCrLf
End Sub

The following code would enable or disable the Close option on MyFormMenu:

Commandbars("MyFormMenu").Findcontrol(Tag:="Close").Enabled = True / False

You can also use the visible property the same way.

HTH
Dale
 
J

Jon Lewis

CommandBar buttons are an Office object so Access can indeed set the
msoButtonUp & msoButtonDown states. (msoButtonDown gives a depressed ticked
box effect).

Set a reference to the Office library and then something like this should
work for you where "RightClick" is the custom shortcut menu and "CheckBox"
is the menu item .

Public Function Toggle()
Dim CBS As Office.CommandBars
Dim CB As CommandBar
Dim CBB As CommandBarButton
Set CBS = Application.CommandBars
Set CB = CBS("RightClick")
Set CBB = CB.Controls("CheckBox")
CBB.State = Not CBB.State
Set CBB = Nothing
Set CB = Nothing
Set CBS = Nothing
End Function

You can also use the CommandBarButton's enabled property in the same way (
e.g. CBB.Enabled = False).

HTH
 
M

Mark Andrews

I can't get the State property to work? I can change the caption, make it
enabled or disabled or even turn it into a combo box. I tried this code as
well as trying to set State to msoButtonDown, msoButtonUp or msoButtonMixed.

Would you have any actual working examples I could get?

Mark
 
J

Jon Lewis

yes - the code I posted.

Save it in a standard module.

Create a new popup toolbar, called "RightClick". Add a custom command and
call it "CheckBox". For the On Action property of the command use the
function Toggle and set the Shortcut Menu "RightClick" as the Shortcut Menu
Bar for your control.

Right click your control and the command "CheckBox" will be unchecked. Left
click it (of course it will disappear). When you right click the control
again, the "CheckBox" command will be checked (and depressed). Is this not
what you wanted?

HTH
 
M

Mark Andrews

One last question:

This code works fine on a top level menu on the popup menu "RPTPopupMenu" on
a control named Option3:

I tried to get it to work on a second level menu by replacing one line with
Set CBB = CB.Controls("Status").Controls("Option1")

The user would choose Status/Option1

However that doesn't seem to work? In debug mode it looks like CBB is
referring to the right control.

Any tips?

Thanks again for your help,
Mark



Public Function Toggle()
Dim CBS As Office.CommandBars
Dim CB As CommandBar
Dim CBB As CommandBarButton

Set CBS = Application.CommandBars
Set CB = CBS("RPTPopupMenu")
Set CBB = CB.Controls("Option3")
CBB.State = Not CBB.State
Set CBB = Nothing
Set CB = Nothing
Set CBS = Nothing
End Function
 
J

Jon Lewis

Dim CBS As Office.CommandBars
Dim CB As CommandBar
Dim CBC As CommandBarControl
Dim CBB As CommandBarButton

Set CBS = Application.CommandBars
Set CB = CBS("RPTPopupMenu")
Set CBC = CB.Controls("Status")
Set CBB = CBC.Controls("Option1")

CBB.State = Not CBB.State

Set CBB = Nothing
Set CBC = Nothing
Set CB = Nothing
Set CBS = Nothing

HTH
 
M

Mark Andrews

Thanks that looks the same to me, but I'll try it out in a few days when I
return from vacation.

Thanks for your help,
Mark
 

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