Delete

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,
Using the "DoCmd.RunCommand acCmdDeleteRecord" statement, how do I set this
to works silently?
I have set the SetWarnings to False but I get an error message saying
"cannot delete now" or words to that effect.
If I comment out the SetWarnings Statement the record is deleted but I am
prompted which I want to avoid.

Regards

John
 
There could be several reasons why Access can't delete now.

Examples:
a) The form is unbound.

b) The form is at a new record, where there is nothing to delete.

c) There is an entry in progress that cannot be saved (e.g. required field
missing), and so the delete cannot occur.

d) The form's AllowDeletions property is No, or the user does not have
permission to delete.

e) The focus is in a text box where the user has entered something invalid,
such as 1/16/ in a date field, or "two" in a number field, or backspaced out
characters in a required field. Access won't let them out of the box until
they fix the entry or press <esc> to undo it.

f) The event you are using is unsuitable.

This solves some of the problems above (b and c):

Private Sub cmdDelete_Click()
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If
End Sub

Other options for deletion without confirmation include using the
BeforeDelConfirm event of the the form to suppress the confirmation.

Or you can delete from the RecordsetClone of the form:

If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
With Me.RecordsetClone
.Bookmark = Me.Bookmark
.Delete
End With
End If
 
Thanks Again Allen

Regards

John

Allen Browne said:
There could be several reasons why Access can't delete now.

Examples:
a) The form is unbound.

b) The form is at a new record, where there is nothing to delete.

c) There is an entry in progress that cannot be saved (e.g. required field
missing), and so the delete cannot occur.

d) The form's AllowDeletions property is No, or the user does not have
permission to delete.

e) The focus is in a text box where the user has entered something
invalid, such as 1/16/ in a date field, or "two" in a number field, or
backspaced out characters in a required field. Access won't let them out
of the box until they fix the entry or press <esc> to undo it.

f) The event you are using is unsuitable.

This solves some of the problems above (b and c):

Private Sub cmdDelete_Click()
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If
End Sub

Other options for deletion without confirmation include using the
BeforeDelConfirm event of the the form to suppress the confirmation.

Or you can delete from the RecordsetClone of the form:

If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
With Me.RecordsetClone
.Bookmark = Me.Bookmark
.Delete
End With
End If
 
Back
Top