Solved

Call VBA script in Access 2003

Posted on 2011-09-16
11
474 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

18 Experts available now in Live!

Get 1:1 Help Now