Retrieving number of records to be deleted

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.

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

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

message
news:[email protected]...
 
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
 
David C. Holley said:
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

More efficient would be

strSQL = "SELECT Count(*) FROM tblTransports WHERE txtType = 'W';"
set rs = CurrentDb.OpenRecordSet(strSQL, dbOpenForwardOnly)
Debug.Print rs(0)
 

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

Back
Top