Add method of the CommandBars collection

C

Cameron

I am using Access 2003 and I am going through a tutorial at
http://msdn.microsoft.com/en-us/library/aa662933(office.11).aspx

The tutorial goes into VBA coding and states,"To create a command bar in VBA
code, use the Add method of the CommandBars collection."

The question is how do I do use the Add method of the CommandBars
collection? I click Alt-F11 to open VBA 6.5 within Access 2003 and can't
figure this out nor find a good tutorial for VBA 6.5 to figure this out.

Cam
 
D

Douglas J. Steele

The text directly underneath the line you quote shows you the details of the
Add method.

What the article neglects to point out explicitly, though, is in order to
use the VBA code that follows, you must go in through Tools | References
while in the VB Editor and ensure that you've added a reference to Microsoft
Office 11.0 Object Library.
 
D

David W. Fenton

What the article neglects to point out explicitly, though, is in
order to use the VBA code that follows, you must go in through
Tools | References while in the VB Editor and ensure that you've
added a reference to Microsoft Office 11.0 Object Library.

Does anyone know the application name needed to use the commandbar
interface with late binding?
 
D

Douglas J. Steele

This works for me to list the command bars:

Sub ListCommandBars()
Dim colCommandBars As Object
Dim objCommandBar As Object

Set colCommandBars = Application.CommandBars
For Each objCommandBar In colCommandBars
Debug.Print objCommandBar.Name
Next objCommandBar
Set objCommandBar = Nothing
Set colCommandBars = Nothing

End Sub
 
C

Cameron

Thank you for the info, that helped. Is there a way to find out what
reference a certain command/function is stored like commandbar is stored
within Microsoft Office 12.0 Object Library?

Also, when I ran the following code, I got a compike error: Method or data
member not found. Am I missing another reference?

Public Sub CreatePopUpMenu()
' Creates and displays a sample pop-up menu.
Dim objCommandBar As Office.CommandBar

For Each objCommandBar In Application.CommandBars
If objCommandBar.Name = "My Popup Menu" Then
objCommandBar.Delete
End If
Next objCommandBar

Set objCommandBar = Application.CommandBars.Add _
("My Popup Menu", msoBarPopup)

objCommandBar.ShowPopup _
Application.Width / 2, Application.Height / 2

' To delete this pop-up menu, call the following:
' Application.CommandBars("My Popup Menu").Delete

End Sub
 
D

David W. Fenton

This works for me to list the command bars:

Sub ListCommandBars()
Dim colCommandBars As Object
Dim objCommandBar As Object

Set colCommandBars = Application.CommandBars
For Each objCommandBar In colCommandBars
Debug.Print objCommandBar.Name
Next objCommandBar
Set objCommandBar = Nothing
Set colCommandBars = Nothing

End Sub

Aha, another of those places where the Application object supplies
access without needing a reference (same as with
Application.CurrentDB working without DAO, and
Application.CurrentProject without ADO).

Good to know, as I might need this in one of my current apps.
 
D

Douglas J. Steele

What line of code raises the error?

As to your question about how to find out what reference contains what
objects, there's no easy way that I'm aware of. Once you've added a
reference, you can use the Object Browser (F2 while you're in the VB
Editor), you can look at what objects are within each Reference, but you
really need to know in advance what you're looking for: there are hundreds
(if not thousands!) of references available on most PCs.
 
C

Cameron

Public Sub CreatePopUpMenu() is highlighted yellow and .Width is highlighted
with the cursor.
 
D

Douglas J. Steele

I don't believe that the Application object in Access has properties named
Width or Height.

You'll have to use an alternative method to determine those values.
Unfortunately, I don't have my references handy, so I can't suggest a way.
 

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