Solved

Access - Not able to get record count

Posted on 2016-09-11
4
35 Views
Last Modified: 2016-10-02
I am trying to open a table and count the records.  I keep getting record count is one.  However when i past the code of my select statement into a query i get the number which i am looking for which is 13.
I eventually would like to filter the table to reduce the results.



  1. Dim db As DAO.Database
  2. Dim rs, rs2 As DAO.Recordset
  3. Dim strSQL, RIGACCT, ClientID, dispname, comp, acctno, bal, exp, expdel, EXPDELDATE, eq, eqdel, EQDELDATE, tu, tudel, tuddate As String
  4. Dim pudate, credotes, newpudate As String
  5. strSQL = "SELECT CREDITREPORT.RIGACCT_FK, CREDITREPORT.CLIENTID_FK, CREDITREPORT.DISPLAYNAME, CREDITREPORT.COMPANYNAME, CREDITREPORT.ACCOUNTNUMBER, CREDITREPORT.BALANCE, CREDITREPORT.EXPERIAN," _
  6.        & " CREDITREPORT.EXPERIANDEL, CREDITREPORT.EXPDELDATE, CREDITREPORT.EQUIFAX, CREDITREPORT.EQUIFAXDEL, CREDITREPORT.EQDELDATE, CREDITREPORT.TRANSUNION, CREDITREPORT.TRANSUNIONDEL, " _
  7.        & "CREDITREPORT.TUDELDATE, CREDITREPORT.PULLEDDATE, CREDITREPORT.CREDREPORTNOTES, CREDITREPORT.NEWPULLEDDATE " _
  8.        & "FROM CREDITREPORT;"
  9. Set db = CurrentDb
  10. Set rs = db.OpenRecordset(strSQL)
  11. With rs
  12.    Debug.Print .RecordCount
  13.    Debug.Print strSQL
  14.    Debug.Print db.OpenRecordset(strSQL).RecordCount
  15. End With
  16. Set rs = Nothing
  17. Set db = Nothing
0
Comment
Question by:VGuerra67
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 250 total points (awarded by participants)
ID: 41793450
You can do:
With rs
   .MoveLast
   .MoveFirst
   Debug.Print .RecordCount
   Debug.Print strSQL
   Debug.Print db.OpenRecordset(strSQL).RecordCount
End With

Open in new window

/gustav
1
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 125 total points (awarded by participants)
ID: 41793555
You can also use DCOUNT:

DCOUNT("RIGACCT_FK", "CREDITREPORT")
0
 
LVL 35

Assisted Solution

by:PatHartman
PatHartman earned 125 total points (awarded by participants)
ID: 41796439
The reason to use the DCount() suggestion over the DAO/Movelast is because with the DAO method, you are forcing Access to physically retrieve each row and bring it from the server to your local PC in order to count the fully populated LOCAL recordset.  With the DCount() method, the answer can be determined by the query engine simply looking at a table statistic and not retrieving any data at all.  The larger the row count, the more important the distinction.

Or, if you are welded to the DAO methodology, at least use a totals query:

Select Count(*) as RecCount from CREDITREPORT;

Then when you open the recordset, it contains a single row and that row contains your count.

The DCount() is essentially the same as the query above.  Both return a single value and both will be optimized to use table stats rather than being forced to retrieve individual rows.
0
 
LVL 84
ID: 41825212
Any of the comment would provide the user with the record count
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now