Why are 2 DoCmd statements needed to delete a record?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Why do I need the following 2 lines in order to delete a record? If I comment
out the 2nd line (see below), then it does not delete the record. However,
with both lines, if I opt out of deleting the record by clicking "No" to the
delete prompt, it errors out. Also, with both rows, it deletes the correct
record selected but displays record #0 when it is actually deleting (i.e.
record #4).

1. DoCmd.DoMenuItem acFormBar, acEditMenu, 8, acMenuVer70
2. DoCmd.DoMenuItem acFormBar, acEditMenu, 6, acMenuVer70

Thank you in advance for your help. I am very appreciate for all of your
support!!

geri
 
Try replacing both lines with:
RunCommand acCmdDeleteRecord

RunCommand was introduced 9 years ago, but Microsoft has not got round to
updating its wizards yet.

The wizards frequently give poor examples.
Reasonable delete code might be:
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
 
gg said:
Why do I need the following 2 lines in order to delete a record? If I comment
out the 2nd line (see below), then it does not delete the record. However,
with both lines, if I opt out of deleting the record by clicking "No" to the
delete prompt, it errors out. Also, with both rows, it deletes the correct
record selected but displays record #0 when it is actually deleting (i.e.
record #4).

1. DoCmd.DoMenuItem acFormBar, acEditMenu, 8, acMenuVer70
2. DoCmd.DoMenuItem acFormBar, acEditMenu, 6, acMenuVer70


Gee, is that the old A2, archaric way of deleting a record,
probably code generated by a holdover wizard. Anyway, the
first line is needed to select the record and the second
line deletes the selected item. You do need both lines.

A more modern, less obscure way of doing the same thing is:

DoCmd.RunCommand acCmdDeleteRecord
 
Back
Top