How know if ControlType=acSubForm is SubReport...

  • Thread starter Thread starter @Alex
  • Start date Start date
@

@Alex

I can't find a solution to detect if Control.Controltype=acSubForm is
SubForm/SubReport...

The only way i find is to check for Control.Parent...

Public Sub MySub(obj As Object)
Dim ctl As Access.Control
'....... do something
'..................
For Each ctl In obj.Controls
Select Case ctl.ControlType
Case Is = acSubform
If TypeOf ctl.Parent Is Form Then
Call MySub(ctl.Form)
Else
Call MySub(ctl.Report)
End If
End Select
Next
End Function


Have i any other possibility or not...?

Tnx
@Alex
 
That may be the easiest way to determine the parent's type and you can make
the assumption that the sub-control matches the parent's type.

You could get the source object of the subform/subreport control and then
check for the existence of the source object in the reports collection or the
forms collection. Although, it is possible to include a subform in a report
and it is possible to have an object have the same name in both the reports
collection and the forms collection.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
That may be the easiest way to determine the parent's type and you can make
the assumption that the sub-control matches the parent's type.

You could get the source object of the subform/subreport control and then
check for the existence of the source object in the reports collection orthe
forms collection.  Although, it is possible to include a subform in a report
and it is possible to have an object have the same name in both the reports
collection and the forms collection.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Hi Jhon, i agree whit all... so i mantein my idea.
Usually i do not use a SubForm in a SubReport... so my idea was for
teoretical standard development method.

Tnx
@Alex
 
loops all controls on report, 112 identifies report.
Dim clt As Control
'
For Each ctl In Reports!rptMain
If ctl.ControlType = 112 Then Debug.Print "subreport"

Next ctl
 
Back
Top