Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / July 2005

Tip: Looking for answers? Try searching our database.

Retrieving number of records to be deleted

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Clingeleffer - 28 Jul 2005 05:50 GMT
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)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.