R rdw456 Novice Local time Today, 01:04 Joined Jul 20, 2012 Messages 43 Jan 27, 2017 #1 Hi all I have a report with five subreports and each one has a total which is used in a calculation in the main report. When any of the subreports has no data I get an error on the main form. Thanks Bob
Hi all I have a report with five subreports and each one has a total which is used in a calculation in the main report. When any of the subreports has no data I get an error on the main form. Thanks Bob
HiTechCoach Well-known member Local time Today, 03:04 Joined Mar 6, 2006 Messages 4,353 Jan 27, 2017 #2 I will assume your question is: How to write the calculation so it can handle a sub report with no data? How are you referencing (getting) the data from the sub report to the main report? One possible solution is to add five HIDDEN (visible = false) text boxes to the main report. Method 1: HasData property Each text will hold the total for one sub report by using a control source similar to: control: txtSub1Total Code: =IIf([Sub1].[Report].[HasData], Nz([Sub1].[Report].[txtTotal], 0), 0) Methid 2: IsError() function Example: control: txtSub1Total Code: =IIf(IsError([Sub1].[Report].[txtTotal]), 0, Nz([Sub1].[Report].[txtTotal], 0)) Substituting with your control names for your reports. You should then have five textbox controls all with valid data or Zero. Now you can total the five controls without errors Example: Code: =[txtSub1Total] + [txtSub2Total] + [txtSub3Total] + [txtSub3Total] + [txtSub5Total]
I will assume your question is: How to write the calculation so it can handle a sub report with no data? How are you referencing (getting) the data from the sub report to the main report? One possible solution is to add five HIDDEN (visible = false) text boxes to the main report. Method 1: HasData property Each text will hold the total for one sub report by using a control source similar to: control: txtSub1Total Code: =IIf([Sub1].[Report].[HasData], Nz([Sub1].[Report].[txtTotal], 0), 0) Methid 2: IsError() function Example: control: txtSub1Total Code: =IIf(IsError([Sub1].[Report].[txtTotal]), 0, Nz([Sub1].[Report].[txtTotal], 0)) Substituting with your control names for your reports. You should then have five textbox controls all with valid data or Zero. Now you can total the five controls without errors Example: Code: =[txtSub1Total] + [txtSub2Total] + [txtSub3Total] + [txtSub3Total] + [txtSub5Total]
R rdw456 Novice Local time Today, 01:04 Joined Jul 20, 2012 Messages 43 Feb 2, 2017 #3 Thanks it pointed me in the right direction and made me change my approach
HiTechCoach Well-known member Local time Today, 03:04 Joined Mar 6, 2006 Messages 4,353 Feb 3, 2017 #4 Glad we could assist. Good luck with your project.