Solved

Call VBA script in Access 2003

Posted on 2011-09-16
11
478 Views
Last Modified: 2012-05-12
Hello,

I've potentially missed something really straightforward here but:

How can I assign a VBA script ("macro1") to a custom toolbar button in Access 2003?

I can do it in Excel no problem, but Access seems to only list the macros created using the GUI, rather than those created using the VBA editor.

Thanks

Josh
0
Comment
Question by:bedsingar
  • 5
  • 3
  • 3
11 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 400 total points
ID: 36549349
In the customize windows, use the 'On Action' property of the button in question and simply type the name of the function into the textbox like so:

YourFunctionName()
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36549411
I don't have a copy of Access 2003 on hand at the moment (we have upgraded to 2007), but as I recall the On Action property for command bar controls had an associated list of Macros that automatically showed in a drop-down list.

This listing does not include your VBA functions - you simply have to know the name of the function needed and type it into the On Action property as I described in my last comment.
0
 

Author Comment

by:bedsingar
ID: 36549456
On another note ... I've just realised that there isn't a 'custom button' in the customise toolbar menu. -Which would make this alltogether more difficult!

I'll set up a form and try suggestion on there.

Thanks

Josh
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 61

Expert Comment

by:mbizup
ID: 36549481
<<I've just realised that there isn't a 'custom button' in the customise toolbar menu.>>

Do you mean a blank button that you can apply your own image, action etc to?

That definitely does exist...

0
 

Author Comment

by:bedsingar
ID: 36549525
Yes I do,

But normally (And In XL) you would ...

Right click tool bar
click customize
goto macros
to find the custom button command

However clicking all macros in Access just lists macros created with the GUI, and not a custom button
... any ideas where it may be hiding?
0
 
LVL 11

Assisted Solution

by:datAdrenaline
datAdrenaline earned 100 total points
ID: 36549543
>> On another note ... I've just realised that there isn't a 'custom button' in the customise toolbar menu. <<

That is not true.  You can add all the custom buttons you want.  I, like mbizup, does not have A2003 on hand at the moment, but if I recall correctly, the custom button is under the File option when creating toolbars through the interface provided in A2003.  If you cannot find it, you can create one programmatically with some 'one time use' code, or just have your app build your toolbar programmatically at every application start.

Also, it is important to know that mbizup was quite literal when she used the term "Function".  The code you want the OnAction property to call has to be declared as Function ... not a Sub ...
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36549573
<< the custom button is under the File option >>

My grey cells are pretty old, so I didn't want to actually say that :-)

But now two of us remember it being under the File option.

That gives me a lot more confidence!
0
 
LVL 11

Expert Comment

by:datAdrenaline
ID: 36549682
>> My grey cells are pretty old <<

... I forget ... what were we talking about? ... hmmm ... it had to be regarding what one of my 9 kids were doing ... :) ...

Its pretty bad when I the term "kid" in my house represents a unit of time equal to two years as well as my offspring LOL!
0
 
LVL 11

Expert Comment

by:datAdrenaline
ID: 36549697
Oh yes ... the OnAction property ... One more thing to remember, the Function must be declared as Public in a Standard Module that does not share its name with the Function name.
0
 

Author Comment

by:bedsingar
ID: 36549713
Thanks Both,

It's now all clicked into place ... I was trown by the custom button not having the smily face image!

Works a treat - Ta.

Josh
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36549728
Glad to help out!

< what one of my 9 kids were doing >

Time to update your profile... That ninth has been 'on the way' for far too long :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question