Counting records with ADO
Hi
I'm using ADO to retrieve data from unopened wbooks. One of the first tasks
is to get the number of original records from the wsheet but I have hit a
UsedRange
problem.
I've used this for speed:
Query2 = "SELECT COUNT(*) FROM Table1;"
rsData2.Open Query2, rsCon, adOpenStatic
rsCount2 = rsData2(0)
It generally succeeds and returns an accurate count but occasionally it
fails because a wbook has been saved with a huge UsedRange which does not
match the real data. For example doing a Ctrl + End on one wbook showed the
last cell as AF50918 whereas the real last cell was only S98.
I have tried getting the max value using a loop with
Query2 = "SELECT COUNT( column ) FROM Table1;"
But this will not necessarily return the correct count. For example it will
return the count as 2 instead of 6 from this data.
Field1 Field2 Field3
xxx
xxx
xxx
xxx
xxx
xxx
So how do I get the real count when dealing with a UsedRange problem in an
unopened wbook?
T.I.A.
Geoff
|