?
Solved

Call VBA script in Access 2003

Posted on 2011-09-16
11
Medium Priority
?
481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 1600 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
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 
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 400 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Suggested Courses

765 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