Hi Guys,



I'm trying to add a button to my form that would expand/collapse all embedded subforms on the main form. I do this by programmatically checking all controls on top subform and if one of them is also subform (so if subform contains other subform) I'm trying to pass the bottom subform as a form to be checked. Here's my button's code, probably it'll make it easier:

Code:
Public Sub expandCollapse(frm As subForm, value As Boolean)'frm is the first level subform on main form
Dim ctl As Control
Dim sForm As Access.subForm
Dim fin As Boolean
Dim found As Boolean




fin = False


Do Until fin
    found = False
    frm.Form.SubdatasheetExpanded = value
    For Each ctl In frm.Form.Controls
        If ctl.ControlType = acSubform Then
            Set sForm = ctl
            If sForm.LinkChildFields <> "" And sForm.LinkMasterFields <> "" Then
                sForm.Form.SubdatasheetExpanded = False 'here I get the error. I can check sForm.Name but can't access sForm.Form
                found = True
                Exit For
            End If
            Set sForm = Nothing
        End If
    Next ctl
    If found = False Then
        fin = True
    Else
        fin = False
        Set frm = sForm
    End If
Loop


End Sub
I receive error 2455 "You entered an expression that has invalid reference to the property Form/Report." What did I do wrong?

Robert