Hi all,
Does anyone know how to retrieve the number of records to be deleted that is
displayed in the
You are about to delete N record(s).
message box? Preferably at the OnDelete event.
Thanks in advance,
John
Allen Browne - 28 Jul 2005 06:02 GMT
The Delete event fires once for each record being deleted.
It would therefore be possible to use a Form level variable to count the
number of records being deleted.
In the General Declarations section of the form (top of the module, with the
Option statements):
Dim lngDeleteCount As Long
In the form's Delete Event:
lngDeleteCount = lngDeleteCount + 1
In the form's BeforeDelConfirm:
MsgBox "Abount to delete " & lngDeleteCount & " record(s)"
In the form's AfterDelConfirm:
lngDeleteCount = 0
Note that this is for an MDB, not an ADP where the events don't fire in that
order. Also, assumes you have confirmation turned on under:
Tools | Options | Edit/Find | Confirm.

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> Hi all,
>
[quoted text clipped - 9 lines]
>
> John
David C. Holley - 28 Jul 2005 13:06 GMT
One option would be use a SELECT query that utilizes the same WHERE
criteria as the DELETE query. If the query is a saved object, you can
execute DCount() on it to get the number of records OR if the WHERE
statement will change periodically, you could use DAO to open the
recordSet, move to the last record and get the value from there.
(Roughly)
strSQL = "SELECT * FROM tblTransports WHERE txtType = 'W';"
set rs = CurrentDb.OpenRecordSet(strSQL, dbOpenForwardOnly)
rs.movelast
Debug.print rs.RecordCount
> Hi all,
>
[quoted text clipped - 8 lines]
>
> John
Dirk Goldgar - 28 Jul 2005 15:33 GMT
> One option would be use a SELECT query that utilizes the same WHERE
> criteria as the DELETE query. If the query is a saved object, you can
[quoted text clipped - 8 lines]
> rs.movelast
> Debug.print rs.RecordCount
More efficient would be
strSQL = "SELECT Count(*) FROM tblTransports WHERE txtType = 'W';"
set rs = CurrentDb.OpenRecordSet(strSQL, dbOpenForwardOnly)
Debug.Print rs(0)

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)