icons for custom shortcut menus?

K

Kim M.

I just created a custom shortcut menu using the "double macro" method and
associated it with a textbox. Works great.

My question concerns how to get the little icon to appear to the left of the
command on the shortcut menu. Incidentally, the only command on my custom
shortcut menu is "Edit Hyperlink." Normally the icon for this is that globe
with the chainlink, but on my custom menu, the spot where it would normally
appear just shows up as a blank space.

Thanks,
Kim M.
 
A

Albert D. Kallal

Kim M. said:
I just created a custom shortcut menu using the "double macro" method and
associated it with a textbox. Works great.

My question concerns how to get the little icon to appear to the left of
the
command on the shortcut menu. Incidentally, the only command on my custom
shortcut menu is "Edit Hyperlink." Normally the icon for this is that
globe
with the chainlink, but on my custom menu, the spot where it would
normally
appear just shows up as a blank space.

Thanks,
Kim M.

Well, you can use VBA code to "set" the icon. However, if you going to use
VBA code to "set" the icon, then you might as well just use code to create
the menu bar in the first place.

The code to create one right click button is:

Dim cB As CommandBar
Dim c As CommandBarControl

On Error Resume Next
Set cB = CommandBars.Add("TestC2", msoBarPopup, False, True)

If Err.Number = 0 Then
Set cB = CommandBars("Testc2")
CommandBars("Form Design").Controls("Hyperlink...").CopyFace
Set c = cB.Controls.Add(msoControlButton)
c.Caption = "Option1"
c.OnAction = "=msgbox('hello')"
c.PasteFace
End If

On Error GoTo 0
Me.ShortcutMenuBar = "testc2"

the above code would go in the forms on-load event. However, you could
actually run the above code once at application startup time and leave out
the above line that sets the menu bar

eg:

Me.ShortcutMenuBar = "testc2"


You would then simply set the above value in the "other" tab of the
properties sheet in design mode.

I suggest this approach if you need that right click menu in "many" places
in the application.

I don't think there is a way to set the icon(s) when you build those
custom menus with the macro approach.
 
K

Kim M.

Albert D. Kallal said:
Well, you can use VBA code to "set" the icon. However, if you going to use
VBA code to "set" the icon, then you might as well just use code to create
the menu bar in the first place.

The code to create one right click button is:

Dim cB As CommandBar
Dim c As CommandBarControl

On Error Resume Next
Set cB = CommandBars.Add("TestC2", msoBarPopup, False, True)

If Err.Number = 0 Then
Set cB = CommandBars("Testc2")
CommandBars("Form Design").Controls("Hyperlink...").CopyFace
Set c = cB.Controls.Add(msoControlButton)
c.Caption = "Option1"
c.OnAction = "=msgbox('hello')"
c.PasteFace
End If

On Error GoTo 0
Me.ShortcutMenuBar = "testc2"

the above code would go in the forms on-load event. However, you could
actually run the above code once at application startup time and leave out
the above line that sets the menu bar

eg:

Me.ShortcutMenuBar = "testc2"


You would then simply set the above value in the "other" tab of the
properties sheet in design mode.

I suggest this approach if you need that right click menu in "many" places
in the application.

I don't think there is a way to set the icon(s) when you build those
custom menus with the macro approach.
 
K

Kim M.

Thanks Albert. Actually I will not need this particular right-click menu
very often (just four text boxes on two forms). So if I don't want it
associated with the whole form, but only these particular text boxes, where
would I paste this code?

(Frustrating that the icons don't carry over to custom toolbars
automatically if using standard commands...)

Thanks!
Kim M.
 
A

Albert D. Kallal

Kim M. said:
Thanks Albert. Actually I will not need this particular right-click menu
very often (just four text boxes on two forms). So if I don't want it
associated with the whole form, but only these particular text boxes,
where
would I paste this code?

Ok, I will suggest that it was just one form, then place the code in one
form.

However, y ou have 4 seperate places you need this.

Also, I am not 100% clear what code (option) is supposed to run when you
right click?

Also, is this a2007, or a previuous verson? In versions prior to 2007 you
can use the user interface (mouse) to build a right click custom menu and
not have to write any code at all.

However, in 2007 you have to use your macro apporach, OR you can use code as
we are doing.

I don't not know which of the above applies to your case. So, we just use
code here then....

I would suggest you place the code in a "standard code module" (call it
basMenus) or whatever you like.

The code would be:

Sub CreateRightClickMenu

Dim cB As CommandBar
Dim c As CommandBarControl

On Error Resume Next
Set cB = CommandBars.Add("TestC2", msoBarPopup, False, True)

If Err.Number = 0 Then
Set cB = CommandBars("Testc2")
CommandBars("Form Design").Controls("Hyperlink...").CopyFace
Set c = cB.Controls.Add(msoControlButton)
c.Caption = "Option1"
c.OnAction = "=msgbox('hello')"
c.PasteFace
End If


end sub


Then, in your startup form, go:

Call CreateRightClickMenu

Open up those two forms in design mode, and specify the shortcut menu for
the controls (you remove the macro setting you have for the 4 controls, and
simply place in the NAME of the right click menu we made. In the above, that
name used is Testc2

In the above, the onAction code is simply a msgbox "hello" command. It is
not 100% clear what your code does now. If the field your clicking on is a
regular text field with a file name that you want to launch, then change :

c.OnAction = "=msgbox('hello')"

to

c.OnAction = "=MyHyperLink()"

Then in your standard code module, we can have:

Public Function MyHyperLink()


Dim frmControl As Control

Set frmControl = Screen.ActiveControl

Application.FollowHyperlink frmControl.value


End Function

Note that the above code assume the text box on the form is a plane Jane
regular text box, NOT a hyperlink field on the form....
 
K

Kim M.

Hi Albert,

I am in Access 2007. It is just two forms (two text boxes per form) that I
want this to affect. And yes, it is for the right-click shortcut menu.
BUT... for the remainder of the controls on the same forms, I want the
default shortcut menus to appear, not my custom one. The fields in question
are text fields with data type (of field in underlying table) set to
"hyperlink." The only thing we ever do with these fields is set up the
hyperlink, and having all the other choices was confusing people, so thought
I would simplify the shortcut menu for them.

I'll give your code a whirl -- thanks so much.
Kim M.
 

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