TeeSee said:
Sorry ...I misinformed. It appears this code runs correctly the error
I get is after I get the Access generated info box asking if okay to
proceed with the delete. If I answer YES all is ok but if I answer NO
i get run time error 2501 "The runSQL action was cancelled". Could you
now then please advise how to properly handle this situation.
That "error" is always raised when your code requests an action that is
subsequently cancelled. In this case, your code requested the execution of
a delete query, but then it was cancelled by the user. Assuming you want to
allow the user the ability to cancel the action, you need to use
error-handling to trap for the error that is raised when they do, and ignore
it. For example,
'----- start of code -----
Private Sub cmdDelete_Click()
On Error GoTo Err_Handler
Dim strSQL As String
strSQL = "Delete * From tblCDMRvalues WHERE ynDelete=Yes;"
DoCmd.RunSQL strSQL
Exit_Point:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
End If
Resume Exit_Point
End Sub
'----- end of code -----
Note that, the above code represents a simple case where you don't have
anything else to do in the procedure after the RunSQL is cancelled, so
execution resumes from the error-handler at Exit_Point, regardless of the
exact error. There could easily be more elaborate situations, where you
resume at any of several locations depending on the nature of the error or
where it occurred.