Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ISERROR Question

Status
Not open for further replies.

blindlemonray

Technical User
Nov 24, 2003
130
GB
can anyone tell me why this does not work

On a control in a report I am using as the control source
Code:
[No_of_app]/[tgt]
but sometimes this gives me a divsion by zero error so I thought I would try
Code:
=IIf(IsError([No_of_app]/[Tgt Appts]),0,[No_of_app]/[Tgt Appts])
But the report still displays the same error!!!!

Any ideas much appreciated.

 
Try:
Code:
=IIf([Tgt Appts]=0,"",[No_of_app]/[Tgt Appts])

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Don't write an expression that might return a string or might return a number. Pick one or the other. You can throw Null in as a viable value:

=IIf([Tgt Appts]=0,Null,[No_of_app]/[Tgt Appts])

You might also want to return 0 rather than Null.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Many thanks folks both work very well. But just being curious, do you know why did the iserror not work?
 
No idea why IsError() doesn't trap the error. Most expressions can be written to avoid errors which is the best practice.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Duane - right as always. Stole that example directly from Microsoft site - I should know better. I usually substitute zero or null in my calculations.

Also from Microsoft:
ISError "Returns a Boolean value indicating whether an expression is an error value."
That is, if it gets a return that evaluates to an error number, it returns 'true'.

You still got the 'divide by zero' error because you were still dividing by zero.



Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Many thanks to all, you'all been very hepful.... damn i love this website!!!

[2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top