Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Key Violation Errors - Can you trap them?

Status
Not open for further replies.

ChemistZ

Programmer
Oct 30, 2001
70
US
I have a delete query that runs off a button on a form. If the user types in the value of a record that can not be deleted due to referential integrity rules, I want a message of my own to come up that says they can't do it. I tried debug.print and got dataerr=8058 and then in the Form's OnError event I put an If statement that checks for that error number but I still get the key violation error message and I never see my own. Since the query runs off of a command button, I also put the If statment in the OnError event of the button but I still get the key violation message. Any ideas?????
 
What I've done in the past is write a quick lookup query or perhaps use a psuedo DSum() to see if records exist for the given key in a child table. If the records exist, I would then branch to my event handling routines based on x rules. I usually set warning off then just execute a simple delete. I have used the referential integrity settings under relationships also. It is a safe option for insuring data integrity, u may want to consider using it if not already. htwh Steve Medvid
"IT Consultant & Web Master"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top