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

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
 
D

Duane Hookom

Use a control source in your text box on your main report like:
=IIf([subrptMySub].Report.HasData, [subrptMySub].Report.Sum_Of_Unit_Price,
0 )
 
A

Allen Browne

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top