Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with deleting a record Error 2501 1

Status
Not open for further replies.

Triacona

Technical User
Jun 11, 2009
462
GB
Dear All,
Thanks for a great forum, like the upgrade! [smile]

I have a problem deleting a records.

I have made my own message box to inform the user that they are deleting the record.

The problem is if they click Yes, another message box appears and says:

Message Box said:
Relationships that specify cascading deletes are about ot cause 1 record(s) in this table and in related tables to be deleted.
Are you sure you want to delete these records? - Yes No Help

If the user chooses Yes, then it is fine and the record is deleted, with all linked records, great, exaclty what I want, except for the extra message box...

I could live with that, BUT, if the user then decides, oh no I don't want to delete the record, and clicks No.

The following error occurs:
Run-time error '2501' said:
The RunCommand action was canceled

This will serve to confuse users.

Is there a way to get rid of the secondary message box(below)?:
Message Box said:
Relationships that specify cascading deletes are about ot cause 1 record(s) in this table and in related tables to be deleted.
Are you sure you want to delete these records? - Yes No Help

So I just have my MsgBox?

My code is below:
Code:
[COLOR=blue]Private Sub[/color] QuestDeleteEntire_Click()
[COLOR=blue]On Error GoTo[/color] Err_QuestDeleteEntire_Click



[COLOR=blue]If[/color] msgbox("Are you sure you want to delete this record?", vbYesNo, "DELETE RECORD!!") = vbYes [COLOR=blue]Then[/color]

    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
    
[COLOR=blue]End If[/color]

Exit_QuestDeleteEntire_Click:

    'Me.[Forms.QuestionnaireFormClose].Requery


[COLOR=blue]Exit Sub[/color]
Err_QuestDeleteEntire_Click:

    [COLOR=blue]If[/color] Err.Number = 2501 [COLOR=blue]Then[/color]        
        msgbox "Record not deleted"
    [COLOR=blue] Else[/color]
        msgbox Err.Description
     [COLOR=blue]End If[/color]
    
    [COLOR=blue]Resume[/color] Exit_QuestDeleteEntire_Click
    
[COLOR=blue]End Sub[/color]
Your help is greatly appreciated! [bigsmile]
Thanks you!


Thank you,

Kind regards

Triacona
 
Private Sub QuestDeleteEntire_Click()
On Error GoTo Err_QuestDeleteEntire_Click

If msgbox("Are you sure you want to delete this record?", vbYesNo, "DELETE RECORD!!") = vbYes Then

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

End If


Exit_QuestDeleteEntire_Click:

'Me.[Forms.QuestionnaireFormClose].Requery


Exit Sub

Err_QuestDeleteEntire_Click:

If Err.Number = 2501 Then
msgbox "Record not deleted"
Else
msgbox Err.Description
End If

Resume Exit_QuestDeleteEntire_Click

End Sub

Thank you,

Kind regards

Triacona
 
What about this ?
...
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Dear PHV,

AWESOME thanks so so much! [2thumbsup][bigsmile]
It works!
Have a star! [smile]
It was quite a frustrating problem, thanks again!

Thank you,

Kind regards

Triacona
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top