Solved

Access 2001 VBA Event Procedure Templates

Posted on 2011-02-14
12
629 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
ID: 34889604
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 - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 250 total points
ID: 34889765
"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
ID: 34889790
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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 1

Author Closing Comment

by:JeffEdmunds
ID: 34889848
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
ID: 34889863
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
ID: 34889883
"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
 
LVL 75
ID: 34889910
"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
ID: 34889918
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
ID: 34890019
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
ID: 34890111
No need to change points.  

mx
0
 
LVL 1

Author Comment

by:JeffEdmunds
ID: 34890231
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
ID: 34890270
"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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…

860 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