Wizard's delete command

R

Robert

If you use the wizard to drop a delete button on a form, it generates the
following code:
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Why doesn't it just do DoCmd.RunCommand acCmdDeleteRecord ?

Robert
 
J

Jeanette Cunningham

Robert,
it does this to keep compatibility with older versions of Access that used
this code. It does a similar thing for other button code it generates.

Jeanette Cunningham
 
A

Allen Browne

The Wiz. code is really ancient, not not good code.

Try something like this:
If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then RunCommand acCmdDeleteRecord

What this does is to undo any changes that are in progress (since you are
going to kill the record anyway), and also avoids the error when there is no
record to delete.
 
R

Robert

Thanks.
Allen Browne said:
The Wiz. code is really ancient, not not good code.

Try something like this:
If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then RunCommand acCmdDeleteRecord

What this does is to undo any changes that are in progress (since you are
going to kill the record anyway), and also avoids the error when there is
no record to delete.
 
A

Access User

I came upon this posting as I have tried this 'wizard' thing myself and found
it did little more than make an obnoxious sound. That having been said,
here's the event click code

Private Sub Command96_Click()

On Error GoTo Err_Command96_Click

If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then RunCommand acCmdDeleteRecord

Exit_Command96_Click:

Exit Sub

Err_Command96_Click:
MsgBox Err.Description
Resume Exit_Command96_Click

End Sub

that I have modified per your posting....no compilation problems but when
clicked, the cmd button results in a message claiming

"The command or action 'DeleteRecord' isn't available now" :-(

?????
 
A

Allen Browne

Is this form bound to a table or query?

Is its AllowDeletions property set to Yes?

Can you edit the records in this form, or is it read-only?

If it is a secured database, do you have adequate permissions?
 

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