RunCommand acCmdDeleteRecord

  • Thread starter Thread starter WTC
  • Start date Start date
W

WTC

I have the following commands in a Private Sub

RunCommand acCmdSelectAllRecords
RunCommand acCmdDeleteRecord


Now when this command is executed, a popup from MS ACcess comes up
confirming to delete selected records. I was wondering what would be the
response to say yes, instead of the user choosing. I already gave the user a
choice prior to these commands.

TIA
 
If Me.Dirty Then Me.Undo
DoCmd.SetWarnings False
RunCommand acCmdSelectAllRecords
RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
 
Allen,
So would this be good code for a generic cancel button on a data entry form?
And a generic delete record button on non data entry forms?

If Me.Dirty Then Me.Undo
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True


David
 
A Cancel button should not delete the record. It should only undo any
changes, and optionally close the form.
Private Sub cmdCancel_Click()
If Me.Dirty Then Me.Undo
DoCmd.Close acForm, Me.Name
End Sub

A Delete button should undo any changes, check you are not at a new record,
and remove the record with a warning:
Private Sub cmdDelete_Click()
If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
End Sub
 
Back
Top