Access 2007-2019
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
Home   News   Courses   Tips   Templates   Forums   Help   Order   Contact   Logon  
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
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
			'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:


Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Account Login
Online Theater
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Waiting List
Production Schedule
Collapse Menus
Live Chat
Customer Support
WalkThru Tutorials
Consulting Services
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Video Tutorials
MYOLP Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Terms of Sale
Live Chat
General Info
Support Policy
Contact Form
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

YouTube Channel    LinkedIn

Blog RSS Feed