Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

True Count of Records in Subform 1

Status
Not open for further replies.

Stangleboy

Programmer
May 6, 2002
76
US
I have been through several posts on the site searching for a code to count the number of records in a SubForm and display in a field on the main form. There are several posts but they are parts and pieces of bigger code. I wrote a simple piece of code on the display field on "Got Focus", but it errors out on me.

Me.[Subform Control Name].Form.Recordset.RecordCount

The form is called "frm_Course" and the subform is called "frm_SubEmpl" also the primary field in the subform is "EmpID" if needed.

I even tired,
=Count([Me!frm_SubEmpl!EmpID]) in the field on the main form itself but error'ed out again.

Any help and time in this would be great assistance, also when replying please just do not post "Use the so-and-so command", please provide example with the data above, that saves me alot of time, thank you.
 
on the subform
txtBxCount: =count([EmpID])
this can be hidden if desired

On the main form
txtBxSubFrmCount: =[NameOfSubFormControl].form![txtBxCount]
 
However in the main forms on current event this should work fine.

Private Sub Form_Current()
Me.txtBxSubFrmCount = Me.subFrmControlName.Form.RecordsetClone.RecordCount
End Sub

This renders much faster.
 
Perfect, I didn't think about doing the work on the subform and then displaying it on the main form!!!
Thank you!
 
However, you will see a delay this way. The other way is instantaneous.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top