Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RecordCount is too smart !

Status
Not open for further replies.

thekon

Programmer
Dec 13, 2001
35
GR
Public Sub test()
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT Somefield FROM SomeQuery WHERE ID=" & Forms![MyForm]![CodeID] & " AND Field2 like 'Ç.2*'")
Debug.Print rst.RecordCount
End Sub

This gives me always the total number of records returned from SomeQuery. No rst.MoveLast, no nothing. I thought the logical would be to return 1 if records are returned or 0 if there are no records.

Thanks in advance for help.
 
That's why it is called RecordCount. It counts the number of records returned by a query.
As for a question, what are you asking?
 
If your asking how to test whether or not the query return records you can test if the recordcount is greater than 0.

JesCat
 
Usually if you use recordCount property immediately after opening a recordset, it shows 1 if the recordset is not empty or 0 if the recordset is empty.
If u populate the recorset with movelast, movefirst, then shows the actual number of records in recordset.
In this particular case, it shows the number of records of the source query [/b]without using movelast.[/b] This is my problem. I want recordcount property to behave as usual.

Sorry for my English :)
 
Continuing.....
The SomeQuery I used in the sub as source has 8 records and the SELECT clause returns 3 records. RecordCount after set statement for recordset is 8 !!! Thats my problem
 
I'm not familiar with recordcount working the way you discribed however you can simply test to see if recordcount is greater than 0. For example

if ( rst.recordcount > 0 ) then
do whatever
else
do whatever
end if
 
theKon,

I know what u mean. Ur expecting to have to populate the recordset first ie movelast, and then movefirst. b4 getting true count.
When i do this, i always get either 1 or 0.
The only time u should get the true count, is if you query against a table, rather than select * from. ie:

set rs = db.openrecordset("tablename")

that way, u should get the correct number of records. Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top