Counting the number of controls in a sub form!!!!

Kango

Registered User.
Local time
Yesterday, 16:44
Joined
Mar 11, 2004
Messages
29
Hi All,

How do i through Vba count the number of controls that are in my subform?.

I am sure this is easier then it sounds?

Thanks
 
The code is the same as counting controls in a regular form, but you need to include a .form after the subform so that it accesses it as a form and not another control.

Code:
Sub CountSubControls()
    Dim ctl As Control
    Dim i As Integer
    
    For Each ctl In Forms!frmMainForm!subform.Form
        i = i + 1
    Next ctl
    
    MsgBox "Total number of controls is " & i
End Sub
 
Hey!

Thanks for doing that. I am just using the code now, will hopefully work!!!

Thanks Again!!!
 

Users who are viewing this thread

Back
Top Bottom