ReportViewer IIf expression in text box returns #ERROR

14,213

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

But I think the real answer is here.

Share:
14,213
Sam
Author by

Sam

I'm a graduate from UW-Stevens Point, entrepreneur, freelance developer, thinker, and eSports enthusiast. I currently own SJC Media LLC and work on independent programming projects.

Updated on June 14, 2022

Comments

  • Sam
    Sam almost 2 years

    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?