Access 2007-2016
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
 
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
MS Access

Custom Error

How to have a Custom Error message instead of the Default Access ones.

There was a question on the forum wanting to change the default error message.

Firstly we need to know the error message we are wanting to trap and change.

You could use a MS Article on how to list all error codes or just google it but this table would be handy for other ones.

Error Codes
CodeDescription
3022The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index t
......

Now open your Form, open the Property Sheet and change to the 'Events' tab and find the 'On Error', click the ellipse (...) and choose Code Builder.

Add the following code:

	Private Sub Form_Error(DataErr As Integer, Response As Integer)
		Debug.Print "DataErr = "; DataErr
	End Sub
	

Now if you run your Form, the error appears, check the Immediate Window and get the error code from there.

Now that we have the error code we can use it, replace the previous code with:

	Private Sub Form_Error (DataErr As Integer, Response As Integer)
	Const conDuplicateKeyViolation = 3022
		If DataErr = conDuplicateKeyViolation Then
			MsgBox "There was a key violation."
			Response = acDataErrContinue
		Else
			'Display a standard error message
			Response = acDataErrDisplay
		End If
	End Sub
	

Now this can easily be changed for any other message.

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

You may want to read these articles from the 599CD News:

 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP