UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Recordset Clone Count, Access 2007    
 
   
reinerm1
post Oct 17 2019, 06:30 AM
Post#1



Posts: 131
Joined: 12-March 14



I'm at a loss, tinkered around this for a day and can't find my mistakes. Here's what I have...

Dim rs1 As Object (also tried As DAO.Object)
Dim lngX1 As Long


If Me.cboDept <> 2010 Then
[Forms]![frmViewSkillByEmp]![frmSkillsYetToLearn].Requery
Set rs1 = [Forms]![frmViewSkillByEmp]![frmSkillsYetToLearn].Form.RecordsetClone
End If

lngX1 = Nz(rs1.RecordCount, 0)

Me.txtYetToEarn = lngX1

Set rs1 = Nothing
lngX1 = 0

In that example, the form "frmSkillsYetToLearn" is datasheet, I can visually count the records. I see and count 36 records, yet the recordcount returns 25. I can't figure out why. I assume that recordsetclone takes an exact clone of the said form recordset, so I can't understand how or why it is counting different than the actual count of records I count on the datasheet form? Can you inform me where I need to inspect / adjust my code? Thanks!
Go to the top of the page
 
arnelgp
post Oct 17 2019, 06:43 AM
Post#2



Posts: 1,510
Joined: 2-April 09
From: somewhere out there...


CODE
If Me.cboDept <> 2010 Then
[Forms]![frmViewSkillByEmp]![frmSkillsYetToLearn].Requery
Me.txtYetToEarn = [Forms]![frmViewSkillByEmp]![frmSkillsYetToLearn].Form.Recordset.RecordCount
End If

--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 
reinerm1
post Oct 17 2019, 06:58 AM
Post#3



Posts: 131
Joined: 12-March 14



Thank you, but I have tried that as well. It still results at a different count?
Go to the top of the page
 
cheekybuddha
post Oct 17 2019, 07:02 AM
Post#4


UtterAccess VIP
Posts: 11,650
Joined: 6-December 03
From: Telegraph Hill


Hi,

Probably the recordset hasn't been fully populated yet.

You can try:
CODE
' ...
Set rs1 = [Forms]![frmViewSkillByEmp]![frmSkillsYetToLearn].Form.RecordsetClone
End If

rs1.MoveLast
lngX1 = rs1.RecordCount
' ...


hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
Larry Larsen
post Oct 17 2019, 07:20 AM
Post#5


UA Editor + Utterly Certified
Posts: 24,375
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi
Going to offer up simple example:
CODE
Dim rst As Object
Set rst = Me.RecordsetClone
On Error Resume Next
rst.MoveLast
On Error GoTo 0
Me.txtYetToEarn.Value = rst.RecordCount


Going to assume the reference to the forms is external to the current form..??

thumbup.gif

--------------------
"Time...We have exactly the same number of hours per day that were given to Helen Keller, Pasteur, Michaelangelo, Mother Teresa, Leonardo da Vinci, Thomas Jefferson, and Albert Einstein"
H. Jackson Brown
Go to the top of the page
 
reinerm1
post Oct 17 2019, 07:56 AM
Post#6



Posts: 131
Joined: 12-March 14



THANK YOU ALL! I'd say you folks are dead on. I added the .MoveLast and now every time, the result is accurate. Again, THANK YOU!
Go to the top of the page
 
dmhzx
post Oct 19 2019, 01:31 PM
Post#7



Posts: 7,112
Joined: 22-December 10
From: England


Why are you dimming a recordset and an object?

dim rsWhatever as dao.recordset (This will give you full intellisense, and generally make life easier


and as has been pointed out you do need to movelast to get a reliable count. And depending on what you want to do next may alos want to move first immediately afterwards

Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    12th November 2019 - 03:57 AM