Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding custom toolbar buttons to the Access VB IDE

68 views
Skip to first unread message

Wendell Ocasio

unread,
Feb 2, 2002, 10:40:31 PM2/2/02
to
Is there a way to add a custom toolbar button (that will run VB code) to the
standard toolbar of the VB IDE in Access? I know how to add custom buttons
to the toolbars in the Access window, but the functionality is not there for
the IDE window.

I also tried to programmatically add the toolbar button, and I got it to
appear, set the OnAction property, but when I click on it, nothing happens.

What I'm trying to do is to have a button that closes all code windows
(sometimes I have too many open at once and I want to close them all). I
wrote code that accomplishes that, I want to create a button that will run
this code.

Frank Miller

unread,
Feb 5, 2002, 4:10:12 PM2/5/02
to
Hi Wendell,

My name is Frank Miller. Thank you for using the Microsoft Access
Newsgroups.

I created a small subroutine that displays a MessageBox and called it
"Test".

In the View Menu, Toolbars, Customize, Commands Tab, I selected the Run
Category and added a Run <selection> button to one of the toolbars. In the
properties of the button, I changed Name: from "Run" to "Run Test" and
closed the customize dialog box. Now when I click the button, I get the
MessageBox from my subroutine to appear indicating that the subroutine is
indeed running.

Perhaps this will work with your subroutine as well.

I hope this helps! If you have additional questions on this topic, please
reply to this posting.

Regards, Frank Miller
Microsoft Support

This posting is provided “AS IS” with no warranties, and confers no rights.

Peer-to-peer newsgroups are available to help you interact with other users
of our products including Microsoft " Most Valuable Professionals" - MVP's.
For more information please see
http://communities.microsoft.com/newsgroups/default.asp?icp=GSS&slcid=us

Wendell Ocasio

unread,
Feb 5, 2002, 8:45:11 PM2/5/02
to
Thank you for your response.

I am unable to get it to work like you described. I addedthe "Run" toolbar
button, and changed the name to "Run MySubroutine". The new button behaves
just like the regular "Run" toolbar button: if the cursor in the selected
code window is located within a subroutine, it will run that subroutine,
otherwise it will present a window with all public subroutines for me to
select which one to run. In fact, I can change the name to anything I want
(even without the "Run") and still get the same functionality. It seems
like the name only affects what is displayed in the screen if you select
"image and text", not the actual action.

I suspect the reason it worked when you tried it is because the cursor was
still inside the "Test" subroutine you just created (that's what happened
when I tried it the first time). If you still can, can you try it with the
code window for Test closed and see if it still works? If so, then I'm
doing something wrong. Thanks again.

Wendell Ocasio


peter walker

unread,
Feb 6, 2002, 1:23:04 PM2/6/02
to
I have a very simple VBA IDE addin available from my site.
Its an Access 2000 version but it may still be loadable in A2002.
I shows how to hook VBA IDE menus and fiddle with code panes and code.
Simple as it is, it may be somewhat advanced for you but your welcome to
download it and play.

see...
http://www.users.bigpond.com/papwalker/LINKS.HTML
for the DemoVBAAddin.Vba link

hth
peter walker

"Wendell Ocasio" <ocas...@yahoo.com> wrote in message
news:u614ai8...@corp.supernews.com...

Frank Miller

unread,
Feb 6, 2002, 5:46:45 PM2/6/02
to
Hi Wendell,

Ouch! You are correct. If the subroutine does not have focus, it doesn't
fire and I can't locate any other way to do this.

Perhaps Peter Walker's code will do what you want.

Wendell Ocasio

unread,
Feb 8, 2002, 9:20:46 PM2/8/02
to
Can you tell me how to install this Addin into Access (I have 2000)?

"peter walker" <papw...@ozemail.com.au.nospam> wrote in message
news:0Fe88.1015$BE4....@newsfeeds.bigpond.com...

peter walker

unread,
Feb 9, 2002, 12:37:14 AM2/9/02
to
Download the VBA file.
Place in a folder of your choice.
Open msaccess2000 with a blank database.
Create a new std module
create an new sub called say junk.

Using the file menu - open project and select file
Make sure the project explorer is open (press ctrl+r if not)
Now you should see at least two projects in the tree
the demoaddin and your database.

The addin project has 1 form, 1 std module and 1 designer.
To view the code for the form or designer, select it in the explorer tree
and use the right mouse button to bring up the context menu and select view
code.

To actually use the project...
On the file menu near the bottom you will see 'Make addindemo.dll'
Selecting this will create the dll in the desired folder.

Now go to the add-ins menu and open the add-in manager.
Select the add-in and tick loaded/unloaded


You will now notice that the popup menu for the code window has two new
items near the bottom, ZeusLogit, ZeusError they will insert text into the
code window (they don't actually do much other than that). Use your new
module and sub to play.

Be careful about where you insert the text<g>\

Feel free to pervert the project as much as you like.
This is an advanced topic but can really make life easier being able to
create you own IDE tools.

hth
peter walker
"Wendell Ocasio" <ocas...@yahoo.com> wrote in message

news:u695abm...@corp.supernews.com...

Wendell Ocasio

unread,
Feb 9, 2002, 9:54:13 PM2/9/02
to
I don't think what you describe can be done in the regular A2000 version
that comes with Office Professional. There is no option for "open project"
or "make .dll" in my Access IDE. I think I would need the full version of
Visual Basic to do that, or maybe Office Developer, which I don't have
either. Correct me if I'm wrong


"peter walker" <papw...@ozemail.com.au.nospam> wrote in message

news:Tu298.3011$BE4....@newsfeeds.bigpond.com...

peter walker

unread,
Feb 9, 2002, 10:26:43 PM2/9/02
to
With Access 2000 on there are **TWO** MDI windows. Microsoft Access and
Microsoft Visual Basic, the latter opening when developing code.
The Open project menu item is under file in the Microsoft visual basic
window not the access window.
Like I said, open a new module then use the file menu, don't go back to
access.

peter walker
"Wendell Ocasio" <ocas...@yahoo.com> wrote in message

news:u6bo70a...@corp.supernews.com...

Wendell Ocasio

unread,
Feb 10, 2002, 11:11:12 AM2/10/02
to
Of course I'm aware of the Visual Basic MDI window in Access, how do you
think I code in the first place? That was the basis of my original
question. In the regular Access window, adding new toolbar butttons is
simple, my question was about adding new toolbar buttons to the VB IDE
window.

My point in that in my Access 2000 version, the only options under the
"File" menu when a module is open are:
Save (project)
Import file...
Export file...
Remove (module)
Print...
Close and return to Microsoft Access

The options you are referring to, "open project" and "make .dll" are not
there. You must have Microsoft Office Developer Edition (or the full Visual
Basic product).

Here is a quote from the MOD documentation in MSDN:

Creating COM Add-Ins with Visual Basic for Applications
See Also

While you've always been able to use COM add-ins in VBA, in the past another
tool, such as Microsoft® Visual C++® or Microsoft® Visual Basic®, was
required to create those add-ins. Now you can create your own COM add-ins in
VBA with Office 2000 Developer without the need for external development
tools

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odecore/htm
l/deconcreatingaddinsinvisualbasicforapplications.asp

Since I don't have MOD, I guess I'm out of luck for now. I can install a
pre-compiled .dll VB IDE add-in, but I cannot create one. The good news for
me is that the place where I work is getting the full VB 6.0 product for me
anyway, so then I'll have more stuff to work with.


"peter walker" <papw...@ozemail.com.au.nospam> wrote in message

news:MHl98.4180$BE4....@newsfeeds.bigpond.com...

peter walker

unread,
Feb 10, 2002, 11:28:04 AM2/10/02
to
I apologise.
I have had it so long (since beta...and I never really used the MOD I didn't
realise it wasn't standard.)
It's not the sort of thing you play around with all the time/
I can email you the raw code modules, if that will help.

chastened
peter walker


"Wendell Ocasio" <ocas...@yahoo.com> wrote in message

news:u6d6thq...@corp.supernews.com...

peter walker

unread,
Feb 10, 2002, 1:20:02 PM2/10/02
to
Ok I have ported the commandbar hooks to work with out any addins.
A form / class module and std module is all that's needed. The form being
the instance of the class I need to receive the command bar events. (being
slightly less fragile than a global variable holding a class)
It does require the following references

Office
C:\Program Files\Microsoft Office\Office\MSO9.DLL
Microsoft Office 9.0 Object Library

**which you should have.

VBIDE
C:\Program Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB
If it's available and registered then you will find it in the references
under ...
Microsoft Visual Basic for Application Extensibility ...

**which I think you should have.

If anyone is *still* interested after this debacle, post to the thread and
I'll post the code and details. There is not that much code and detail but
maybe more than the ng would like.

are we allowed to post attachments here (strictly text of course)?

peter walker
<snip>


Wendell Ocasio

unread,
Feb 10, 2002, 7:39:12 PM2/10/02
to
I'm still interested. If you want you can send it to ocas...@yahoo.com
(just like that, it's so full of spam already I don't worry about it
anymore)

I already have VBIDE and Office as references. I was trying to write some
code that would insert the toolbar button for me. See if you can tell
what's wrong with it.

I wrote the following procedure (as a function) that closes all the open
code windows (my goal in the first place):

Public Function CloseAllCodePanes()
Dim cdp As VBIDE.CodePane

For Each cdp In Access.Application.VBE.CodePanes
cdp.Window.Close
Next cdp
End Function

That works fine. If I run it, all the code windows close. Now I want to
attach that piece of code to a toolbar button. The following code adds a
new toolbar button to my standard toolbar at the 4th position from the left,
with the text caption close. The OnAction property makes it a call to the
CloseAllCodePanes() function:

Public Sub AddStandardButton()
With Access.Application.VBE.CommandBars.Item("Standard").Controls
.Add msoControlButton, 1, , 4
With .Item(4)
.Caption = "Close"
.Style = msoButtonCaption
.OnAction = "=CloseAllCodePanes()"
End With
End With
End Sub

When I run that piece of code it creates the toolbar button like I wanted,
but clicking it doesn't do anything. If I go into "customize" and
right-click "properties" for that button, OnAction is not one of the
properties (it is not a property in any of the buttons in the VB window, it
is a property in the buttons in the regular Access window). My theory is
that the "OnAction" property is not implemented in the VB window. To test
that theory, I changed the first line to

With Access.Application.CommandBars.Item("Database").Controls

which added the button to the Database toolbar in Access window instead.
Then, clicking the button closed all the code windows. Of course, I don't
want to have to switch to the Access window just to click a button. The
bottom line question then is: is there a way (other than the OnAction
property) to attach a procedure to a toolbar button in the VB IDE window?


"peter walker" <papw...@ozemail.com.au.nospam> wrote in message

news:MOy98.4716$BE4....@newsfeeds.bigpond.com...

Tony Toews

unread,
Feb 10, 2002, 11:46:20 PM2/10/02
to
"Wendell Ocasio" <ocas...@yahoo.com> wrote:

>Is there a way to add a custom toolbar button

FWIW there was a posting recently indicating that a custom toolbar was
responsible for bloating an MDB which a compact did not clean out.
But importing did.

Tony


--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm

peter walker

unread,
Feb 11, 2002, 7:33:09 PM2/11/02
to
If you look in the object browser for the office commandbarButton you will
see the click event. You hook this by declaring the button using
'withevents' in a class.
I am sending the mdb to you, but here is a preview of some code.

'module code.....
Public Function SetMenu(strMenuName As String, strCaption As String) _
As Office.CommandBarButton

Dim oCmdBar As CommandBar
Dim oCmdBarControl As Office.CommandBarControl
On Error Resume Next
'try setting to existing commandbar
Set oCmdBar = oHostApplication.CommandBars(strMenuName)
If oCmdBar Is Nothing Then
'create a new commandbar
Set oCmdBar = oHostApplication.CommandBars.Add(strMenuName)
End If
oCmdBar.Visible = True
'add items to the commandbar
Set oCmdBarControl = oCmdBar.Controls.Add(MsoControlType.msoControlButton)
oCmdBarControl.Caption = strCaption
oCmdBarControl.Style = MsoButtonStyle.msoButtonCaption
'return event and deref
Set SetMenu = oCmdBarControl
Set oCmdBarControl = Nothing
Set oCmdBar = Nothing
End Function

'class module code....
Private WithEvents mnuItem1 As Office.CommandBarButton

Private WithEvents mnuItem2 As Office.CommandBarButton

Private WithEvents mnuItem3 As Office.CommandBarButton

Public alive As String
Private Sub mnuItem1_Click _
(ByVal Ctrl As _
Office.CommandBarButton, _
CancelDefault As Boolean)
On Error Resume Next
Dim m As Long
Dim n As Long
Dim x As Long
Dim y As Long
Dim proc As String
Dim proc2 As String
VBE.ActiveCodePane.GetSelection m, n, x, y
proc = VBE.ActiveCodePane.CodeModule.ProcOfLine(m, vbext_pk_Set)
proc = VBE.ActiveCodePane.CodeModule.Parent.Name & "." & proc
msgbox "current procedure " & proc
End Sub

the above are code snippets.

sorry about the delay, my 'borg / human' switch broke and I needed some
sleep

peter walker

"Wendell Ocasio" <ocas...@yahoo.com> wrote in message

news:u6e4m6h...@corp.supernews.com...

snip


peter walker

unread,
Feb 11, 2002, 7:39:46 PM2/11/02
to
Download mdb from....
http://www.users.bigpond.com/papwalker/cmhook.mdb

watch the wrap (if any)

peter walker


Wendell Ocasio

unread,
Feb 12, 2002, 9:43:48 PM2/12/02
to
Thanks so much for all of that.

Using the click event works well, but there is a problem: there must be an
open reference to the class that hooks the event. Since the whole point of
this is to do things in a development environment, as soon as I break or
reset the project during debugging the reference is gone and the event will
not fire, unless I recreate the instance of the class (form or otherwise).

It sounds like the bottom line is: to add extensibility to the VB editor, I
must write a COM add in, which I can't do without the full VB6 or MOD.
Hopefully I will get VB6 soon.

Thanks again for all your help with this. I learned a lot, and I think I
start creating my own COM addins as soon as I get the product.


JOSEPHDubio

unread,
Mar 29, 2002, 10:38:29 AM3/29/02
to

"Wendell Ocasio" <ocas...@yahoo.com> wrote in message
news:u5pcogb...@corp.supernews.com...

JOSEPHDubio

unread,
Apr 9, 2002, 4:43:33 AM4/9/02
to

"Wendell Ocasio" <ocas...@yahoo.com> wrote in message
news:u695abm...@corp.supernews.com...
0 new messages