Solved

Access 2001 VBA Event Procedure Templates

Posted on 2011-02-14
12
626 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 - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Top 1 of each supplier 55 55
Exporting Access Tables as CSV 3 23
Access 2013 DoCmd.TransferSpreadsheet Not Working in Win 10 8 27
SQL Group on First occurrence 9 24
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

770 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