UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Custom Error Message For Violating Index, Access 2016    
 
   
DeborahSV
post May 13 2018, 12:48 PM
Post#1



Posts: 99
Joined: 14-September 10



Hello,
I have a table that has a unique index that combines two fields (DepositDate and DepositBatch). If a user enters a duplicate into the form, they get an error message "The 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...etc...." How can I replace this with a customized message so I can explain in simple language what the user must change? What is this error?
Thank you!
Go to the top of the page
 
Jeff B.
post May 13 2018, 01:29 PM
Post#2


UtterAccess VIP
Posts: 10,128
Joined: 30-April 10
From: Pacific NorthWet


If Access is throwing an error (and from your description, it is), then your error handling routine (you DO have an error handling routine, right?) can "catch" that error and provide a different message, one of your design.
Go to the top of the page
 
DeborahSV
post May 13 2018, 01:38 PM
Post#3



Posts: 99
Joined: 14-September 10



Thank you.
I have error handlers on the various events of the form, but my question here is: how do I "catch" this particular error? What is the number of this error? If I put a customized messagebox in the On Error event of the form, it could potentially run for other errors as well, right?
Go to the top of the page
 
Jeff B.
post May 13 2018, 02:01 PM
Post#4


UtterAccess VIP
Posts: 10,128
Joined: 30-April 10
From: Pacific NorthWet


This may raise the hackles of some, but I use the error message that crops up to determine the error number. If that isn't working, I insert a "Stop" command just before my error handler. That way, when the error triggers and the code 'heads for' the error handler, it'll stop and you can use the Immediate window (or a debug.print err.number) to see the number. Then add an If/Then to your error handler to 'catch'.
Go to the top of the page
 
DeborahSV
post May 13 2018, 02:41 PM
Post#5



Posts: 99
Joined: 14-September 10



Truth be told, I had tried something like that before posting, and I got error number 0, and I was just worried that maybe 0 is a "generic" error number and my message would be displayed for some other error. But I'll just go ahead and put in an If err.number = 0... on the form's on error event. Thanks.
Go to the top of the page
 
theDBguy
post May 13 2018, 03:15 PM
Post#6


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Hi Deborah,

Error = 0 means no error. Perhaps, when you checked, the error was already cleared.

Try using the Form’s Error event to trap system errors like this.

Hope it helps...
Go to the top of the page
 
GroverParkGeorge
post May 13 2018, 05:55 PM
Post#7


UA Admin
Posts: 33,536
Joined: 20-June 02
From: Newcastle, WA


Right. This is a record level error and it is raised in the FORM's Error event. It will be reported as DataErr, rather than Err.
Go to the top of the page
 
DeborahSV
post May 13 2018, 06:26 PM
Post#8



Posts: 99
Joined: 14-September 10



Thanks to both of you. Yes, I got the right number using DataErr (it's 3022), and I have a nice customized message working now. I had a hunch that "0" didn't make sense for the error number... Thanks for the edification.
Go to the top of the page
 
theDBguy
post May 14 2018, 12:40 PM
Post#9


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Hi Deborah,

Nice work! We're all happy to assist. Good luck with your project.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    26th September 2018 - 01:46 AM