Solved

Access 2001 VBA Event Procedure Templates

Posted on 2011-02-14
12
620 Views
Last Modified: 2012-05-11
When you add an Event Procedure for a control in Access 2007, the program inserts the VBA code to get you started. I assume this comes from a template. Is it possible to edit that template so it will automatically insert the basic error-handling code I use whenever I add new Event Procedures? As I understand it, there are third-party applications which will allow you to do this kind of thing, but I don't want to buy something like that if I don't have to.

Thanks!
0
Comment
Question by:JeffEdmunds
  • 6
  • 3
  • 3
12 Comments
 
LVL 11

Accepted Solution

by:
Runrigger earned 250 total points
Comment Utility
It is not possible no.

I suggest that you make your own template for error handling and paste it between the 1st/last line of the event.
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 250 total points
Comment Utility
"Is it possible to edit that template"
No

However ... this awesome tool is free ... and includes templates you can easily customize ....and add to every event procedure or code module:

http://www.mztools.com/v3/mztools3.aspx

Invaluable tool!

mx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
The only customizing you can do is

Private Sub btnMyButton_Click()
   ' some code
End Sub

to

Public Sub btnMyButton_Click()
   ' some code
End Sub

This would allow you to Call the procedure from an external module ...

mx
0
 
LVL 1

Author Closing Comment

by:JeffEdmunds
Comment Utility
Splitting points because technically Runrigger answered the question "Is it possible", but DatabaseMX gave exactly what I was looking for if it wasn't possible. Copying & Pasting my own code template is what I've been doing, but mztools looks like it might handle that better.

Thanks to you both!
0
 
LVL 11

Expert Comment

by:Runrigger
Comment Utility
I would have gone with MX's response personally as that's the more satisfying response.

MX, I did not know that you could change Private/Public switches on event procedures! How do you do that?
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"but mztools looks like it might handle that better."
Guaranteed ... and a whole-lot-more :-)

I use MZTools hourly - seriously.  So many cool features, including the VBA Find & Replace function. I have all sorts of custom templates for different things.  

And if you have more than one computer, you can simply take the INI file to that system, and you are Good To Go.

mx
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"How do you do that?"
Just change Private to Public .. right in the code ...

Occasionally it is handy (or necessary) to call an event procedure code from elsewhere.  In fact, technically ... if the event has say a Cancel parameter, you can even pass 0 or -1 ... for example.

mx
0
 
LVL 1

Author Comment

by:JeffEdmunds
Comment Utility
I can request that the points be reassigned to MX if you're OK with it - just wanted to be fair. :)
0
 
LVL 11

Expert Comment

by:Runrigger
Comment Utility
LOL!

@MX:  When you suggested changing Private to Public, I assumed that you meant that there was an option toggle to make all event procedures default to Public! I should have read your response properly!

Entirely up to you regarding the points allocation, its a hassle for you, not us, I am not particularly worried either way and I am sure that MX isn't one to split hairs either.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
No need to change points.  

mx
0
 
LVL 1

Author Comment

by:JeffEdmunds
Comment Utility
OK, I'll leave the points as they are.

I just downloaded and installed MZ Tools, added my error-handler template, tested it and it works very well. I love the variables you can add so it automatically plugs in things like the method type and name... very handy!

I need to spend some time exploring this thing to see what else it can do, but have to be careful... 5:00pm comes very quickly when I get a new toy. :)   "So, let me get this straight. You downloaded a tool to increase productivity, then spent 4 hours messing with it and got nothing else done?"

Seriously, though, I greatly appreciate it. This was a very helpful tip!
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"I love the variables you can add so it automatically plugs in things like the method type and name... very handy!"

Yes ... that is HUGE !!!  No more hard coding Procedure names in the error trapping !
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

772 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

12 Experts available now in Live!

Get 1:1 Help Now