Click here to Skip to main content
15,843,031 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to modify some old legacy VB6 code that uses a DAO Jet database.

The problem is the RecordSet RecordCount property.
The database contains 17953 records.

The code does a MoveFirst and MoveLast, which is supposed set the RecordCount, but the RecordCount property only returns 17855 (98 short)

The code then loads ALL the 17953 records into a ListView, so all records are accessed and are correctly loaded into the Listview, but even then the RecordCount still only returns 17855 !

Is there any other way to get the RecordCount to be correct?

What I have tried:

The simplified code is something like this.

Dim Dsi As DAO.Recordset
Set Dsi = Dbs.OpenRecordset(tblMessages, dbOpenTable)
...
Dsi.MoveLast
Dsi.MoveFirst
...
'Simple loop
Do Until Dsi.EOF
(load record into ListView)
Dsi.MoveNext
Loop
...
Posted
Updated 4-Jan-18 1:29am
Comments
F-ES Sitecore 4-Jan-18 4:51am    
If you need to access all records then use a clientside cursor so you don't need to movedlast\movefirst. As for your missing records, dump the IDs or whatever to a file\log to identify which records are missing and see if you can see any common link.

1 solution

Start by checking the database:
SQL
SELECT COUNT(*) FROM MyTable
will tell you how many rows there are. Use Access to run the query and see what you get back. At a guess - and without access to your DB that's all it can be - you are confusing an ID number with a row number, and there are "gaps" in the IDs where rows have been deleted.

And do your users a favour: Don't just dump 18,000 rows into any display control: it's not a management number for humans. Page it, let them search it, filter it: but displaying much more than 50 rows is unreasonable because it takes too long to find the row you are interested in. And it makes your app slow. Combine the two, and your users will hate the app, and for good reason.
 
Share this answer
 
Comments
n4tm 4-Jan-18 9:52am    
That query does return the correct count of records, as 17953
RecordCount still returns 17855

However, your solution does the job!
Thank you.

PS. I was only using that number of records as a test. The user normally only sees about 100 maximum, usuallly less.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900