Why are 2 DoCmd statements needed to delete a record?

G

gg

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
 
A

Allen Browne

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
 
D

Duane Hookom

I would use code like
DoCmd.RunCmd acCmdDeleteRecord 'or something like that
 
M

Marshall Barton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top