Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Customizing Ms Access Error Message about Referential Integrity violation

Posted on 2004-04-08
7
Medium Priority
?
466 Views
Last Modified: 2008-03-06
Hi,

My goal is the following:

Have a form with a listbox in it. I select and enrtry from it, then press a command button, the record is erased. Deletion is done programatically via a Sub, using an SQL DELETE FROM clause.

Issue:

When the underlying record to erase exists in other tables, a referential integrity violation message comes up. It appears below. How do I intercept the error generated and substitute it for  something custom made that the user can understand.

"Ms Access can't delete 1 record(s) in the delete query du to key violations and 0 record(s) du to lock violations"
0
Comment
Question by:mabelanger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 2

Expert Comment

by:michaelbartolotta
ID: 10789029
mabelanger,
Just perform a SQL Select on the OTHER table(s), if there are any records with matching keys, post a message and skip the Delete.
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10790171
Use behind the button code like this:

On Error GoTo err_btnDelete
CurrentDb.Execute ("delete * from YourTable where tableID=" & Me.tableID), dbFailOnError
err_btnDelete:
If Err = 3200 Then
   MsgBox "Key: " & Me.tableID & " is still related to other records"
Else
   MsgBox "Severe error: " & Err.Number & " " & Err.Description
End If

Nic;o)
0
 
LVL 54

Accepted Solution

by:
nico5038 earned 360 total points
ID: 10790180
Hmm, forgot the jump after the succesfull deletion :-(
Use:

On Error GoTo err_btnDelete
CurrentDb.Execute ("delete * from YourTable where tableID=" & Me.tableID), dbFailOnError
goto exit_btnDelete

err_btnDelete:
If Err = 3200 Then
   MsgBox "Key: " & Me.tableID & " is still related to other records"
Else
   MsgBox "Severe error: " & Err.Number & " " & Err.Description
End If

exit_btnDelete:
end sub

Nic;o)
0
 

Author Comment

by:mabelanger
ID: 10793913
Hmm... I see where you're getting.

The following doesn't return anything useful, which is strange:

MsgBox "Severe error: " & Err.Number & " " & Err.Description

With some troubleshooting:

Err.Number returns a zero for a successful deletion as well as for a referential integrity violation.  
In both cases Err.Description returns a blank.  What's the catch? Do I need to put something in the Global section?

0
 
LVL 54

Expert Comment

by:nico5038
ID: 10793964
Strange, I tested this on a defined referential integrety relation violation and got error 3200.

Sure you used the last version I posted ?

Nic;o)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question