Solved

Customizing Ms Access Error Message about Referential Integrity violation

Posted on 2004-04-08
7
389 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
  • 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 90 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now