Solved

Access - Not able to get record count

Posted on 2016-09-11
4
31 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 34

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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 …

762 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

18 Experts available now in Live!

Get 1:1 Help Now