B
botuco via AccessMonster.com
I have a one-to-many relationship from table TbX to TbY with referential
integrity turned on, cascade updates/deletes turned off. I have a form with
a command button to delete records from TbX in it.
As expected, if I try to delete a record from TbX using the command button, I
get an error (Error Number 3200) stating “The record cannot be deleted or
changed because ‘TbY’ includes related records.†I added error handling to
the button to display a custom message. This is what I came up with:
Private Sub cmd_delete_Click()
On Error GoTo Err_cmd_delete_Click
DoCmd.RunCommand acCmdDeleteRecord
Exit_cmd_delete_Click:
Exit Sub
Err_cmd_delete_Click:
Select Case DataErr
Case 3200
MsgBox “you cannot delete this recordâ€
Exit Sub
Case Else
Resume Exit_cmd_delete_Click
End Select
End Sub
Now, when I click the button nothing happens. The record is not deleted but
no message box is displayed.
I have also tried adding the error handling to the forms OnError event but
when I do this, Error 3200 is still displayed. I have searched this and
other forums without finding any answers.
Any suggestions?
integrity turned on, cascade updates/deletes turned off. I have a form with
a command button to delete records from TbX in it.
As expected, if I try to delete a record from TbX using the command button, I
get an error (Error Number 3200) stating “The record cannot be deleted or
changed because ‘TbY’ includes related records.†I added error handling to
the button to display a custom message. This is what I came up with:
Private Sub cmd_delete_Click()
On Error GoTo Err_cmd_delete_Click
DoCmd.RunCommand acCmdDeleteRecord
Exit_cmd_delete_Click:
Exit Sub
Err_cmd_delete_Click:
Select Case DataErr
Case 3200
MsgBox “you cannot delete this recordâ€
Exit Sub
Case Else
Resume Exit_cmd_delete_Click
End Select
End Sub
Now, when I click the button nothing happens. The record is not deleted but
no message box is displayed.
I have also tried adding the error handling to the forms OnError event but
when I do this, Error 3200 is still displayed. I have searched this and
other forums without finding any answers.
Any suggestions?