delete 1 record on the continous form

X

xg

I use the wizard to add a button on my continous form's detail band so each
record will have a button for delete action. The wizard gives me these
codes:

Private Sub cmdDel_Click()
On Error GoTo Err_cmdDel_Click

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

Exit_cmdDel_Click:
Exit Sub

Err_cmdDel_Click:
MsgBox Err.Description
Resume Exit_cmdDel_Click

End Sub

The problems are:
1. If user click the button, select NO to cancel, the number of records are
not same. Need to refresh? How?
2. I do not want the 2nd message box show if user select NO to cancel.
3. Any other simple way to delete the record next to my button?

Thanks.
 
A

Allen Browne

#1. The number of records should be same after you cancel a deletion, but
you may have to scroll up the subform to see the previous records.

#2. You can use the BeforeDelConfirm event of the form to suppress a dialog
or replace it with your own message.

#3. You can replace those 2 DoCmd lines with this one:
RunCommand acCmdDeleteRecord

Better still:

Private Sub cmdDel_Click()
On Error GoTo Err_cmdDel_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
Exit_cmdDel_Click:
Exit Sub

Err_cmdDel_Click:
MsgBox Err.Description
Resume Exit_cmdDel_Click
End Sub
 
A

Allen Browne

What dialog?

You should only receive one.

You can turn it off for this one form by setting the form's Before Del
Conform property to:
[Event Procedure]
Then click the Build button (...) beside this.
Access opens the code window.
Between the "Private Sub..." and "End Sub" lines, enter:
Response = acDataErrContinue
 
X

xg

That's it. Thanks.

Allen Browne said:
What dialog?

You should only receive one.

You can turn it off for this one form by setting the form's Before Del
Conform property to:
[Event Procedure]
Then click the Build button (...) beside this.
Access opens the code window.
Between the "Private Sub..." and "End Sub" lines, enter:
Response = acDataErrContinue

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

xg said:
#2: I just want to suppress the dialog. what code should it be?

thanks.
 

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