Share via

RecordCount

Anonymous
2019-12-11T23:00:50+00:00

I have an Access DB connected to an oracle back-end. RecordCount will not return the actual recordcount but -1 even if rst.movelast is executed before. A loop, however, as shown below, will do the job. What isn't recordcount working? Thanks.

Dim rst as ADODB.Recordset

dim counter as integer

Set rst = New ADODB.Recordset

Strsql = "SELECT FIRST_NAME, LAST_NAME FROM PEOPLE"

rst.Open Strsql, con, adOpenDynamic, adLockOptimistic

debug.print rst.recordcount 'this will always return -1 even if rst.movelast is executed before. What am I missing here?

'The following loop will do the job

counter = 0

Do While rst.EOF = False

rst.MoveNext

counter = counter + 1

Loop

debug.print counter 'this swill show the correct record count

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
2019-12-12T02:16:52+00:00

some recordsets do not support recordcount. I think the odbc driver may have something to do with it.

If you want a count, why do you not execute a "select count(*) from tablename" query?

If the table is linked, you can also use the DCount function.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful