Count Subform Datasheet Records on Main Form (1 Viewer)

dukquack

New member
Local time
Today, 01:03
Joined
Nov 9, 2012
Messages
6
Hi All,

Having a few problems trying to count the number of records in a subform datasheet view and display that count in a text on the main form.

The problem is every solution i have tried is giving me the wrong number, i think this is because the subform has not completely loaded before my main form is grabbing the count?

I was wondering if anybody could help me find a solution.

I have a peice of code below, this code is in a button which will change all fields in a subform datasheet to certain value, could this be modified to instead of changing a value, count records?

Thanks in advance :)

Code:
Dim rst As DAO.Recordset
Set rst = Me![StatusChangeSubform].Form.RecordsetClone

With rst
.MoveLast
.MoveFirst

Do While Not .EOF ' Hmmm.... This code will run until it hits the last record...
.Edit
!CaseStatus = "Pack Sent"
.Update

If Not .EOF Then 'Without this, won't it respond with a "No Current Record" error?
.MoveNext
End If
Loop

End With
Set rst = Nothing
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 10:03
Joined
Jan 20, 2009
Messages
12,851
No need for the complexity.

Place a textbox in the footer of the subform. Give it the ControlSource:
=Count(*)

Place a textbox on the main form. Give it he ControlSource for the one you addeed to the subform:
=subformname.Form.controlname

It doesn't matter that it is a datasheet subform. The footer won't be displayed but it still exists.
 

dukquack

New member
Local time
Today, 01:03
Joined
Nov 9, 2012
Messages
6
That works, but it is giving the wrong number, there are 85,000 records, but the number it is giving is 33.

Is this due to the amount of records or the subform not fully loading before the number is passed onto the text box?

Thanks for your help
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 10:03
Joined
Jan 20, 2009
Messages
12,851
This technique has always worked for me.

You noted in your original post that you keep gettng the wrong number whichever way you try. Maybe the problem is you are mistaken about what count to expect?
 

Users who are viewing this thread

Top Bottom