Certainly by the time controls are being evaluated, the form or report
should be in the collection.
But I'm mystified by why you're using such a roundabout approach.
You certainly don't need to loop through the Reports collection to find a
particular one - Me should work fine.
If you need to put your function in a standard module (where Me is
meaningless), you can pass a reference to the form as an argument, instead
of its name.
But why use the function at all?
Why not just put this in your ControlSource:
=Format(Sum([QuotedJobTotal])+IIf(Me.SubreportWorkInProgress.Form.HasData,Nz
([txtTotSubQuotedJobTotal].[Value],0),0),"$#,##0.00")
<ji********@compumarc.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
At what point is a Form added to the Forms collection or a Report added
to the Report collection? I.e., listed as currently open. The reason
I ask is that I have a subreport for an exclusive separate condition
that may or may not have data. When it does have data its total needs
to be added to the final report total. I used a function like:
Public Function SubreportHasData(strReport As String, strSubReport As
String) As Boolean
Dim rptX As Report
SubreportHasData = False
For Each rptX In Reports
If rptX.Name = strReport Then
SubreportHasData =
Reports(strReport).Controls(strSubReport).Report.H asData
Exit For
End If
Next rptX
End Function
along with a totals ControlSource like:
=Format(Sum([QuotedJobTotal])+IIf(SubreportHasData("rptWorkInProgress","Subr
eportWorkInProgress"),Nz([txtTotSubQuotedJobTotal].[Value],0),0),"$#,##0.00"
)
which seemed to work. It also worked using
Reports("rptWorkInProgress").[Controls]("SubreportWorkInProgress").[Report].
[HasData] directly without a function call. This made me wonder about at what
precise point does it become safe to assume a Form or Report is in the
Forms or Reports collection.
Thanks,
James A. Fortune