467,879 Members | 1,349 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

At what point is a Report added to the Reports collection?

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","Subrep ortWorkInProgress"),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

Nov 20 '05 #1
  • viewed: 1743
Share:
3 Replies
I don't know.
I never use

Reports("rptWorkInProgress").[Controls]("SubreportWorkInProgress").[Report].[HasData]

I always ensure that my Forms and Reports have modules (they don't
really have to have any code, just the HasModule property set to True).

I use the default instance of the Report as Object
as in
Report_WorkInProgress.HasData
(assuming WorkInProgress is the name of the sub report).
When the object is referenced in this way it is not necessary to travel
through its antecedents.

I'm aware that this will open the report if it is not already open. IMO
calling code with a reference to the subreport from the main report is
safe in this respect.

I also use this method when the report is not open:

Here are trivial examples:

Report_Fabrics.Visible = False 'don't show it
Debug.Print Report_Fabrics.HasData 'find out something bout it
Set Report_Fabrics = Nothing 'close it and release it
----
With Report_Fabrics
.Caption = "As of " & Date 'change public property
.Visible = True 'be sure it's open for viewing
End With
----
With Report_Fabrics
If .DoYouReallyWanna() Then ' run a public procedure
Nov 20 '05 #2
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

Nov 20 '05 #3
MacDermott wrote:
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")


Ah. Why use the Reports Collection at all? Good point. I'm not
adding a field from a separate report so your suggestion looks
promising. I'll try it out. I'm still curious about the original
question though.

James A. Fortune

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike Wiseley | last post: by
6 posts views Thread by Bob Alston | last post: by
5 posts views Thread by jmar | last post: by
reply views Thread by kamboj.shalabh | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.