Solved

Call VBA script in Access 2003

Posted on 2011-09-16
11
475 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
 
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

930 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now