Solved

Access database engine cannot find recordset

Posted on 2014-09-22
3
294 Views
Last Modified: 2014-09-22
I define a DAO recordset and shows up in "locals" window and when I hover over its fields lower in the code it has values as exoected, but if I want to count the records, I get an error message as below. What is wrong?

I want to count the total number of records in the recordset. (Stops are there for debugging.)

Set rstIncomes = db.OpenRecordset(rstIncomesSQL, dbOpenSnapshot)
Stop

If DCount("*", "rstIncomes") = 0 Then
   MsgBox "rstIncomes has No records to show"
   Stop
   GoTo Proceed
Else
   MsgBox "rstIncomes has " & DCount("*", "rstIncomes") & "records."
   Stop
End If

Open in new window

error messageerror message
0
Comment
Question by:Fritz Paul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 40336219
DCount can only be used on a table or query, not on a recordset. For a recordset you should use the RecordCount property, as illustrated in the following code snippet:
Dim rstIncomes As DAO.Recordset

Set rstIncomes = db.OpenRecordset(rstIncomesSQL, dbOpenSnapshot)

With rstIncomes
    .MoveLast
    .MoveFirst
    MsgBox "The rstIncomes has " & .RecordCount & " records!"
End With

rstIncomes.Close
Set rstIncomes = Nothing

Open in new window

0
 
LVL 84
ID: 40336226
Or if you simply want a Count of the items:

Dim rst AS DAO.Recordset
Set rst = Currentdb.OpenRecordset("SELECT COUNT(*) AS RecCount FROM YourTable WHERE blah blah blah")

Msgbox "Record count: " & rst("RecCount")
0
 

Author Closing Comment

by:Fritz Paul
ID: 40336233
Thanks for quick and accurate reply.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

734 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