?
Solved

Customizing Ms Access Error Message about Referential Integrity violation

Posted on 2004-04-08
7
Medium Priority
?
480 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
5 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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 …
Suggested Courses

749 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