HowTo: Create a TOP LEVEL custom pulldown menu

B

Bob

access 2k;

I've tried EVERYTHING I can think of to create a custom drop down
menu. I have NO problem creating buttons on an existing menu pulldown.

I would like to add (next to the Help pulldown) a pulldown called
"Bob". As you can see there's 2 versions; but I've tried Dozens!!

here's the code I believe to be the closest I've come to getting it
working:

Dim cb As CommandBar, ctl As CommandBarControl
Set cb = CommandBars("Menu Bar")

' Set ctl = cb.Controls.Add("Bob", Type:=msoControlButton)
Set ctl = cb.Controls.Add(Type:=msoControlButton, Id:="Bob")
With ctl
.BeginGroup = False
.OnAction = "=msgbox('hi there')"
.Visible = True
End With

This will be a pulldown menu, with another button that will do the
OnAction.

tia - Bob
 
J

Juan M. Afan de Ribera

Hi Bob,

if I understand what you want, maybe this example will work for you

Dim cb As CommandBar
Dim ctl As CommandBarControl
Dim btn As CommandBarButton

Set cb = CommandBars("Menu Bar")

Set ctl = cb.Controls.Add(msoControlPopup)

ctl.Caption = "New menu"

Set btn = ctl.Controls.Add

With btn
.OnAction = "=msgbox('hi there')"
.Caption = "Bob"
End With

Set btn = Nothing
Set ctl = Nothing
Set cb = Nothing

HTH

--
Saludos desde Barcelona
Juan M. Afan de Ribera
<MVP Ms Access>
http://www.juanmafan.tk
http://www.clikear.com/webs4/juanmafan
 
B

Bob

Hi Bob,

if I understand what you want, maybe this example will work for you

Dim cb As CommandBar
Dim ctl As CommandBarControl
Dim btn As CommandBarButton

Set cb = CommandBars("Menu Bar")

Set ctl = cb.Controls.Add(msoControlPopup)

ctl.Caption = "New menu"

Set btn = ctl.Controls.Add

With btn
.OnAction = "=msgbox('hi there')"
.Caption = "Bob"
End With

Set btn = Nothing
Set ctl = Nothing
Set cb = Nothing

HTH

Juan;

Yes - that's exactly what I was trying to accomplish!!!
tx very much
curious though; why set btn,ctl,cb to nothing @ the end?

tia - Bob
 
J

Juan M. Afan de Ribera

Well, when you make a reference to an object with

Set variable = some_object

@ the end, when you don't need that variable anymore, you always have to
free resources and free that reference with

Set variable = nothing

if not, your code maybe will be on trouble, and will be exposed to
unexpected things to happen.

--
Saludos desde Barcelona
Juan M. Afan de Ribera
<MVP Ms Access>
http://www.juanmafan.tk
http://www.clikear.com/webs4/juanmafan
 
D

david epsom dot com dot au

curious though; why set btn,ctl,cb to nothing @ the end?

C programmers always thought that real programmers did
their own memory management (because C required that).

That influenced VBA programmers in two ways: People whose
sense of self-importance was tied to the fact that they
were C programmers heaped scorn on people who used languages
with system memory management,

And the C++ programmers who wrote Access 95 and Jet 3
and had trouble getting the memory management right (they
were using C++ and had to do their own memory management)
did not think that the bugs were important enough to be
worth fixing (after all, real programmers do their own
memory management).

Expect all that to slowly change. C# provides full memory
management (moving into the 1950's as a properly designed
language with an obscure and inefficient syntax), so C#
programmers are getting used to the fact that the system
can do memory management better than the programmer.

(david)
 
B

Bob

David

(LOL)

tx for your reply!!

Bob


C programmers always thought that real programmers did
their own memory management (because C required that).

That influenced VBA programmers in two ways: People whose
sense of self-importance was tied to the fact that they
were C programmers heaped scorn on people who used languages
with system memory management,

And the C++ programmers who wrote Access 95 and Jet 3
and had trouble getting the memory management right (they
were using C++ and had to do their own memory management)
did not think that the bugs were important enough to be
worth fixing (after all, real programmers do their own
memory management).

Expect all that to slowly change. C# provides full memory
management (moving into the 1950's as a properly designed
language with an obscure and inefficient syntax), so C#
programmers are getting used to the fact that the system
can do memory management better than the programmer.

(david)
 

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