Link to home
Start Free TrialLog in
Avatar of EricLynnWright
EricLynnWrightFlag for United States of America

asked on

Access record count from subform

In VBA, from a main form, how do I get record count from subform?
ASKER CERTIFIED SOLUTION
Avatar of jambraun
jambraun
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I use a function, something like:

Private Sub fnFormRecCount(frm as form) as long

    Dim rs as DAO.Recordset

    set rs = frm.recordsetclone
    fnFormRecCount = rs.RecordCount
    set rs = nothing

End Function

Then call this function from somewhere in your main form, maybe as the control source of a textbox (which is what I do).  

ControlSource: = fnFormRecCount(me.subFormControlname.Form)

Then, I use the subforms "ApplyFilter" event to requery that textbox.

Private Sub Form_ApplyFilter

    me.parent.txt_RecCount.Requery

End Sub
Thanks for the grade.  Good luck with your project.  -Jim