Solved

Access 2001 VBA Event Procedure Templates

Posted on 2011-02-14
12
621 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
 
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

943 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

10 Experts available now in Live!

Get 1:1 Help Now