Link to home
Start Free TrialLog in
Avatar of JeffEdmunds
JeffEdmundsFlag for United States of America

asked on

Access 2001 VBA Event Procedure Templates

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!
ASKER CERTIFIED SOLUTION
Avatar of Runrigger
Runrigger
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of JeffEdmunds

ASKER

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!
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?
"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
"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
I can request that the points be reassigned to MX if you're OK with it - just wanted to be fair. :)
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.
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!
"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 !