Gettting number of Recs, ADO Open with adOpenForwardOnly, adLockReadOnly

I am trying to speed up a long running process in a clients Access 2013 application by among other things, changing the open of the recordsets involved in the process from

1.  rsIn.Open selectString, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
2.  rsIn.Open selectString, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly

When I was using 1. I could check the number of records in the result set with wkTotRecs = rsIn.RecordCount

I then put a counter on the screen showing the total number of records and which records was being processed.  

'Processing 23 of 125'

I find this to be much more meaningful to the users that the status bar.

When I open with 2., rsin.Recordcount always is -1.

Is there an efficient way to get the number of records in the result set while using format 2.?

I know I could do a count() but that seems like it would be processing the file twice.  One to get the count and one to read the records.  Dcount would also work but that would also increase the overhead, which I am trying to reduce.

I think adCursorLocation can accomplish this but I'm not sure how to set it.
Who is Participating?
Fabrice LambertFabrice LambertCommented:
Since the recordCount property is only reliable after you reach the end of the recordset, and it doesn't matter with forward-only recordsets, I'm afraid the only option is running a count() query.
Limit the query to only one column tho, to reduce server load / data traffic.
You could do a .MoveLast, get the Absoluteposition property, and then .MoveFirst

This technique does not work with a forward-only recordset
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.