If Then Else Statment in Report

T

Thorson

I currently have an if then else statment in my report that adds the sum of
another field to the sum of animal births (if animal births has data). I
would however like this whole equation to=0 if nothing is reported, however
instead it has an #error.

I thought that edited the equation would solve the problem but I'm not sure
how to edit it. This is the orginial eqation:
=(Sum([SumOfExpr4]))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)

This is what I tried editing it to, and it didn't work:
=IIf((SumOfExpr4.HasData),((Sum([SumOfExpr4]))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)),0)
 
T

Thorson

I tried what you suggested making my equation
=(Sum(Nz([SumOfExpr4],0)))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)

My report still returns the answer as #Error

Carl Rapson said:
Try using the Nz function:

=(Sum(Nz([SumOfExpr4],0)))+IIf...

Carl Rapson

Thorson said:
I currently have an if then else statment in my report that adds the sum of
another field to the sum of animal births (if animal births has data). I
would however like this whole equation to=0 if nothing is reported,
however
instead it has an #error.

I thought that edited the equation would solve the problem but I'm not
sure
how to edit it. This is the orginial eqation:
=(Sum([SumOfExpr4]))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)

This is what I tried editing it to, and it didn't work:
=IIf((SumOfExpr4.HasData),((Sum([SumOfExpr4]))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)),0)
 
C

Carl Rapson

Then I would guess there's something wrong with the other part of the
expression. Does the error occur always, or only when there's no data? If
it's only when there's no data, I would guess that HasData isn't returning
False for some reason. I've not had much experience working with the HasData
function, so I don't know why it wouldn't be working the way you expect. It
could possibly be a timing issue; maybe the subreport isn't ready to respond
to the HasData function at whatever point this expression is evaluated.

Sorry I can't be of more help.

Carl Rapson

Thorson said:
I tried what you suggested making my equation:
=(Sum(Nz([SumOfExpr4],0)))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)

My report still returns the answer as #Error

Carl Rapson said:
Try using the Nz function:

=(Sum(Nz([SumOfExpr4],0)))+IIf...

Carl Rapson

Thorson said:
I currently have an if then else statment in my report that adds the sum
of
another field to the sum of animal births (if animal births has data).
I
would however like this whole equation to=0 if nothing is reported,
however
instead it has an #error.

I thought that edited the equation would solve the problem but I'm not
sure
how to edit it. This is the orginial eqation:
=(Sum([SumOfExpr4]))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)

This is what I tried editing it to, and it didn't work:
=IIf((SumOfExpr4.HasData),((Sum([SumOfExpr4]))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)),0)
 
T

Thorson

it only reports an error when [SumOfExpr4] has no data. [SumOfExpr4] is a
field of the query that is used to make the main report, if that changes
anything, but I think you already knew that.

If you don't have any other ideas I'll try reposting my question. Thank you
for your help anyway.


Carl Rapson said:
Then I would guess there's something wrong with the other part of the
expression. Does the error occur always, or only when there's no data? If
it's only when there's no data, I would guess that HasData isn't returning
False for some reason. I've not had much experience working with the HasData
function, so I don't know why it wouldn't be working the way you expect. It
could possibly be a timing issue; maybe the subreport isn't ready to respond
to the HasData function at whatever point this expression is evaluated.

Sorry I can't be of more help.

Carl Rapson

Thorson said:
I tried what you suggested making my equation:
=(Sum(Nz([SumOfExpr4],0)))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)

My report still returns the answer as #Error

Carl Rapson said:
Try using the Nz function:

=(Sum(Nz([SumOfExpr4],0)))+IIf...

Carl Rapson

I currently have an if then else statment in my report that adds the sum
of
another field to the sum of animal births (if animal births has data).
I
would however like this whole equation to=0 if nothing is reported,
however
instead it has an #error.

I thought that edited the equation would solve the problem but I'm not
sure
how to edit it. This is the orginial eqation:
=(Sum([SumOfExpr4]))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)

This is what I tried editing it to, and it didn't work:
=IIf((SumOfExpr4.HasData),((Sum([SumOfExpr4]))+IIf(rptORRMonthlyBirthsCountSubreport.Report.HasData,rptORRMonthlyBirthsCountSubreport.Report.CountOfEarTag,0)),0)
 

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