'Delete record' code

R

Rich Skruch

Using the Command Button Wizard to make a button to delete the current
record, Access inserts the code:

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

What is the difference between that and using:

DoCmd.RunCommand acCmdDeleteRecord

(Access 2002, .mdb is 2000 format)

Thanks,
Rich.
 
D

Dirk Goldgar

Rich Skruch said:
Using the Command Button Wizard to make a button to delete the current
record, Access inserts the code:

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

What is the difference between that and using:

DoCmd.RunCommand acCmdDeleteRecord

(Access 2002, .mdb is 2000 format)

The RunCommand method is newer, simpler, and much to be preferred. The
DoMenuItem method was built into the wizard before the RunCommand method
existed.
 
G

Guest

Also the runcommand typically works with the SINGLE currently selected record
(usually the current one displayed in form view) while the wizard code works
with "multiple selection" (that is when you click the selection bar in the
form and all the records meeting the current filter are therefore selected).
 
D

Dirk Goldgar

JamesK said:
Also the runcommand typically works with the SINGLE currently
selected record (usually the current one displayed in form view)
while the wizard code works with "multiple selection" (that is when
you click the selection bar in the form and all the records meeting
the current filter are therefore selected).

I thought that was an interesting distinction that I hadn't heard of, so
I just tested it. I don't find it to be the case, though -- on my test
form, the wizard code still deletes only one record, even if I select
multiple records before clicking the button. Perhaps I'm missing
something.
 
G

Guest

did clicking the button cause you do "deselect" the records in the form prior
to the butoon code firing. i usually use the wizard code from a toolbar
(where it has worked in my experience). and, yes, i haven't "tested" it in
Access 2003 but it used to work that way. I have another thread here with an
apparent anomoly in Access 2003 so... who knows. I won't try to argue the
the experts.
 
D

Dirk Goldgar

JamesK said:
did clicking the button cause you do "deselect" the records in the
form prior to the butoon code firing. i usually use the wizard code
from a toolbar (where it has worked in my experience). and, yes, i
haven't "tested" it in Access 2003 but it used to work that way. I
have another thread here with an apparent anomoly in Access 2003
so... who knows. I won't try to argue the the experts.

Oh, go ahead -- argue. :)

I checked, and yes, the button was in the form footer, so selecting it
did deselect the records. So I created a button on a toolbar, and had
it call this function:

Function DelRec

RunCommand acCmdDeleteRecord

End Function

I found that if I selected multiple records on a form, then clicked the
toolbar button, all the selected records were deleted. So it still
looks to me like the RunCommand approach does the same thing as the
DoMenuItem apprach, only simpler.

I tested this in Access 2002, by the way, so any differences with A2003
don't come into it.
 

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