delete command button

H

hje

On my form, I created a delete command button. When I
select the button on my form, it correctly provides a
dialogue box verifying that I want to delete the record.
However, the record information it is displaying in the
form in the background is incorrect -- it has already
forwarded to the next record even though I have not
confirmed the deletion yet.

This is misleading because it is not the record I need to
verify for deletion.

Also, if I cancel the deletion, it shows a dialogue box
that says "The DoMenuItem was canceled." What is this?

Does anyone know how to correct for this?
Thanks!!!
 
J

Jesse Avilés

Post the code. The dialogue box is Access way of telling you that the
deletion was canceled.
 
D

Dirk Goldgar

hje said:
On my form, I created a delete command button. When I
select the button on my form, it correctly provides a
dialogue box verifying that I want to delete the record.
However, the record information it is displaying in the
form in the background is incorrect -- it has already
forwarded to the next record even though I have not
confirmed the deletion yet.

This is misleading because it is not the record I need to
verify for deletion.

Also, if I cancel the deletion, it shows a dialogue box
that says "The DoMenuItem was canceled." What is this?

Does anyone know how to correct for this?
Thanks!!!

The record advancing is the standard way the delete-record action works
in Access: the record is prospectively deleted, then you are asked to
confirm it, and then the deletion is either committed or rolled back.
The same thing would happen if you used the Delete Record toolbar button
or the Edit -> Delete Record menu item.

You can get around this several ways. Probably the simplest is to
displaying your own confirmation dialog in the button's Click event, and
then turn warnings off using SetWarnings before executing the command
that deletes the record -- taking great care to turn them back on again,
of course. For example,

'--- warning: air code ----
Private cmdDelete_Click()

On Error GoTo Err_Handler

If MsgBox("Are you sure you want to delete this record?", _
vbQuestion+vbYesNo, "Delete Record?") _
= vbYes _
Then
DoCmd.SetWarnings False
RunCommand acCmdDeleteRecord
End If

Exit_Point:
DoCmd.SetWarnings True
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Sub
'--- end code ----
 

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