How do I set a text box value to 0 if there is no data in the sub.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a text box Sum_Of_unit_price text box in the sub report. I use this
text box value in my main report to calculate the total cost. When there is
no data in the sub report, my main report is showing as #Error.

I have this code

Private Sub Report_NoData(Cancel As Integer)
Sum_Of_unit_price = 0
End Sub

but this is not working. I would really appreciate if some one could help me.

Thanks
 
Use a control source in your text box on your main report like:
=IIf([subrptMySub].Report.HasData, [subrptMySub].Report.Sum_Of_Unit_Price,
0 )
 
If there is no data in the subreport, the text box does not exist, and so
any attempt to refer to it results in #Error. You can avoid that by testing
the HasData property of the report in the subreport control

The ControlSource of the text box on the main report will be something like
this:
=IIf([Sub1].[Report].[HasData], Nz([Sub1].[Report].[Text1],0), 0)
where Sub1 is the name of the subreport control, and Text1 is the name of
the text box in the subreport.
 
Thank you for your help. This one solved my problem.

Allen Browne said:
If there is no data in the subreport, the text box does not exist, and so
any attempt to refer to it results in #Error. You can avoid that by testing
the HasData property of the report in the subreport control

The ControlSource of the text box on the main report will be something like
this:
=IIf([Sub1].[Report].[HasData], Nz([Sub1].[Report].[Text1],0), 0)
where Sub1 is the name of the subreport control, and Text1 is the name of
the text box in the subreport.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sangee said:
I have a text box Sum_Of_unit_price text box in the sub report. I use this
text box value in my main report to calculate the total cost. When there
is
no data in the sub report, my main report is showing as #Error.

I have this code

Private Sub Report_NoData(Cancel As Integer)
Sum_Of_unit_price = 0
End Sub

but this is not working. I would really appreciate if some one could help
me.

Thanks
 
Back
Top