Null Date Parameter, IIf condition generates runtime error.

  • I have a date parameter that is allowed to be null. If the user unchecks the Null box and supplies a date, I want to display that date in a textbox at the top of the report. If they left the checkbox for null checked, I want the text box displaying the date to contain an empty string. This has nothing to do with the data for the report, it is just to show on a printed report what parameter values were chosen.

    All of these expressions for my textbox generate a runtime error: object reference not set to an instance of an object.

    =IIf(IsDate(Parameters!MinimumSaleDate.Value), "Products Sold Since " & Parameters!MinimumSaleDate.Value.ToString, "")

    =IIf(IsNothing(Parameters!MinimumSaleDate.Value), "", "Products Sold Since " & Parameters!MinimumSaleDate.Value.ToString)

    =IIf(Parameters!MinimumSaleDate.Value > 0, "Products Sold Since " & Parameters!MinimumSaleDate.Value.ToString, "")

    Can someone tell me how to test for a null value for a date parameter with the expression writer?

  • I solved this by splitting it into two expressions in two different textboxes. It seems if the user leaves the date parameter null it will cause an error if we reference parameter.value in the expression. So, in one text box I tested for parameter.value = nothing and just left that text box blank. In another text box I tested for parameter.value <> nothing, and then put the parameter.value in the box.

  • Try something like this

    =IIf(IsNothing(Parameters!MinimumSaleDate.Value), "", "Products Sold Since " & IIf(IsNothing(Parameters!MinimumSaleDate.Value), "", Parameters!MinimumSaleDate.Value.ToString))

    I know this looks daft but it evaluates all of the code regardless - So even though your code should work it's trying to set nothing to string

    So If you use an IIf even though it will never be used it should work

    Hope that makes sense

    Cheers

    Andy

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply