Link to home
Start Free TrialLog in
Avatar of mlcktmguy
mlcktmguyFlag for United States of America

asked on

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
to
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.
ASKER CERTIFIED SOLUTION
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could do a .MoveLast, get the Absoluteposition property, and then .MoveFirst

This technique does not work with a forward-only recordset