S
Steve
I have delete query in a form module that can potentially produce a key
violation because it would delete the table's PK which is used as a FK in
another table and referential integrity is enforced. My normal error trapping
method does not work. The only error code the sub produces is zero (I used a
msgbox to display it), but it is definitely producing a key violation and the
deletion is not performed. Any suggestions on how to trap this error so that
I can control how the users react to it? My code is below.
thanks
Steve
Private Sub cmdDelete_Click()
Dim MyResponse As Integer, MyMessage As String
On Error GoTo ErrHandler
MyResponse = MsgBox("Are you sure you want to delete the selected
therapist?", vbInformation + vbYesNo, "Delete therapist?")
If MyResponse = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM tblTherapists WHERE TherapistEmail = '" &
Me.lboTherapists & "'"
Me.lboTherapists.Requery
DoCmd.SetWarnings True
Exit Sub
Else
Exit Sub
End If
ErrHandler:
'Error code goes here
End Sub
violation because it would delete the table's PK which is used as a FK in
another table and referential integrity is enforced. My normal error trapping
method does not work. The only error code the sub produces is zero (I used a
msgbox to display it), but it is definitely producing a key violation and the
deletion is not performed. Any suggestions on how to trap this error so that
I can control how the users react to it? My code is below.
thanks
Steve
Private Sub cmdDelete_Click()
Dim MyResponse As Integer, MyMessage As String
On Error GoTo ErrHandler
MyResponse = MsgBox("Are you sure you want to delete the selected
therapist?", vbInformation + vbYesNo, "Delete therapist?")
If MyResponse = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM tblTherapists WHERE TherapistEmail = '" &
Me.lboTherapists & "'"
Me.lboTherapists.Requery
DoCmd.SetWarnings True
Exit Sub
Else
Exit Sub
End If
ErrHandler:
'Error code goes here
End Sub