Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   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
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

 

 

 

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 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/28/2024 5:02:42 AM. PLT: 0s