Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Trap Form Errors    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Form Errors
William Platt 
     
2 years ago
Another great Tech Help video! Would each error need to be explicitly labeled in the code to capture the error? Could we then use this information to log into a table by trapping the error code, the [FormName], the [FieldName], and the [Date/TimeStamp]? This would provide a comprehensive record of the errors, their context, and when they occurred.

Could we potentially transform this into a GlobalModule? This would allow us to reference it on each form, eliminating the need to duplicate the entire code for each form and making our work more efficient.
Kevin Yip  @Reply  
     
2 years ago
The short answer is no to all your questions, because the Form Error sub is *not* where the error occurs.  In Richard's example, if the user makes an erroneous entry, the error should normally occur in the *AfterUpdate* event.  But you have no way of knowing that, because you are not in the AfterUpdate event.  

The Form Error event only gives you the error code, but not the exact error message (which is contextual, and may be different even for the same error code), nor the line of code that caused the error.  Only the "On Error" statement can give you that info.  

The only way to get the complete info about the error is to put the error handling into each and every procedure in your database, as I said in the other thread ( https://599cd.com/blog/display-comment.asp?CommentID=93969 ).  

Also, an error handler is mainly for trapping errors you don't know about in advance.  If you know what errors would occur (e.g. if you know the user may enter the wrong date), it is better to just *prevent* the error from occurring (with If-Then statements and/or the BeforeUpdate event, as Richard mentions in the video) rather than invoking an error handler.

Thirdly, errors don't always occur in forms.  They may occur in standalone VBA modules, in which case the Form Error event would be useless.

Fourthly, VBA code often involves "cascading events:" procedure A calls proc B, which calls proc C, D, etc.  The only way to pinpoint where an error occurs exactly is to put error handling in A, B, C, etc.  There is no way to get around that.  As I said before, there is no "global" handling of this.  And this is not a shortcoming of Access.  Many other environments are like this too.  

Creating a good error-handling feature is a *prime* task, one that is not always done well even in commercial products.  That's why sometimes we see apps (such as Windows itself) go into an unusable state that requires a restart.
William Platt OP  @Reply  
     
2 years ago
Thank you, very useful information. So this kind of error capturing is for indexed fields with no duplicates that way it tells the person that they have duplicated information. This also could be used as a for wrong format and stuff like that.
Kevin Yip  @Reply  
     
2 years ago
I rarely used the Form Error event in my old job because it doesn't give enough info of the errors; and for the errors it does catch, there is always a way to prevent the error in the first place.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Trap Form Errors.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 5:54:18 AM. PLT: 0s