On Delete Msg Box

G

Guest

I have a database where I coded my forms to display a msg box I created when
deleting a record, instead of the standard access form by using the
setwarning = False for OnDelete action.

This works fine for single record forms, but where I have continuous record
forms and I delete more than one record at a time the msg box comes up for
each record I delete. Is there a way to use code so I can get a msg box like
the standard on delete Access msg which tells you how many records you are
deleting and only shows once?

Thanks,

Kevin
 
A

Allen Browne

When a record is deleted in a form, the Delete event fires for each record,
and the BeforeDelConfirm fires once for the operation.

You can therefore increment a module-level variable in Form_Delete so you
get the count, and then use that count in the confirmation message in
Form_BeforeDelConfirm.

This kind of thing:

1. In the General Declarations section (top of the form's modules, with the
Option statements):
Dim mlngDelCount As Long

2. In Form_Delete:
mlngDelCount = mlngDelCount + 1

3. In Form_BeforeDelConfirm:
If MsgBox("Delete " & mlngDelCount & " record(s)?", vbYesNo) = vbNo Then
Cancel = True
End If
mlngDelCount = 0
Response = acDataErrContinue

This assumes:
a) We are talking about an MDB, not an ADP (where the events are different.)
b) Confirmation is turned on.
 
G

Guest

Thanks Allen, I'll give it a try.

Kevin

Allen Browne said:
When a record is deleted in a form, the Delete event fires for each record,
and the BeforeDelConfirm fires once for the operation.

You can therefore increment a module-level variable in Form_Delete so you
get the count, and then use that count in the confirmation message in
Form_BeforeDelConfirm.

This kind of thing:

1. In the General Declarations section (top of the form's modules, with the
Option statements):
Dim mlngDelCount As Long

2. In Form_Delete:
mlngDelCount = mlngDelCount + 1

3. In Form_BeforeDelConfirm:
If MsgBox("Delete " & mlngDelCount & " record(s)?", vbYesNo) = vbNo Then
Cancel = True
End If
mlngDelCount = 0
Response = acDataErrContinue

This assumes:
a) We are talking about an MDB, not an ADP (where the events are different.)
b) Confirmation is turned on.
 

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