ReportViewer IIf expression in text box returns #ERROR

Sam picture Sam · Oct 19, 2010 · Viewed 14.1k times · Source

I'm using ReportViewer for work and I'm trying to get an IIf expression to work with a few text boxes that are using FormatCurrency(). The reason I needed an IIf statement in the first place was because occasionally on this report, there will be null parameters. The example here is a shipping box that may or may not have a value. If it has a value, say 15, it will format correctly to $15.00. If it doesn't have a value it returns #ERROR. Obviously this won't do.

Here is one IIf statement I'm using on a different report that works totally fine (sets the visibility of a text box):

=IIf(Fields!DATASET_NAME.Value.ToString() <> "DELETE", True, False)

Here is the one that's not working:

=IIf(Parameters!ShipAmt.Value.ToString() <> "", FormatCurrency(Parameters!ShipAmt.Value,2), "")

The IIf seems to work because if I enter a value it will still format correctly, but without a value it still returns #ERROR. Any ideas?

Answer

Hans Passant picture Hans Passant · Oct 19, 2010

Calling ToString() on a null value goes Kaboom. Try IsNot Nothing instead.

But I think the real answer is here.