PDA

View Full Version : Solved: Consisten Record Count??



JKwan
06-27-2007, 12:08 PM
Is there a way that I can get a consistent record count? What I mean is that if I step thru my code, I get the correct record count everytime, however, if I let my code execute, it consistently reports incorrect record count!! This is the code that I am using:

Dim frm As Form
Dim Dehydrators As Control
Dim Separators As Control
Dim Treaters As Control

Set frm = Forms("foundation")
Set Dehydrators = frm.Dehydrators
Set Separators = frm.Separators
Set Treaters = frm.Treaters

NumberOfTreaters = Treaters.Form.Recordset.RecordCount
NumberOfDehy = Dehydrators.Form.Recordset.RecordCount
NumberOfSeparators = Separators.Form.Recordset.RecordCount


Foundation is the main form, the others are sub forms with linking to an ID number. This is driving me a little nutty!

JKwan
06-27-2007, 12:53 PM
I have a slight update (I guess). I don't know if there is a lag (due to the sub form stuff).... This may explain why if I run it thru debug - my record count is correct - during the debug process - the sub form was able to process the join?? Do I make sense?

I solve my problem my putting a 2 second timer to execute my procedure to get the record count. This seem to be doing its trick. Initially, the record is wrong, then the Timer kicks in and then my record count is correct. There had to be a better way to do this, this band aid seem to be so, well, awkward.

mattj
06-28-2007, 08:08 AM
Sometimes recordsets aren't fully populated when they are opened - specifically DAO recordsets. I recommend you open a clone of the recordset, perform a .MoveLast operation to force the recordset to open all records, and then retrieve the count.

HTH
Matt

JKwan
06-28-2007, 08:21 AM
Matt:
Thank you for the tip. .MoveLast is working great. Now, I can remove my band aid!

mattj
06-28-2007, 08:24 AM
Glad it worked for you - on a side note, it's not an error or a bug. It's by design and is intended to increase performance by not making users wait to fully open large recordsets.