Invalid Use of Null

  • Thread starter Thread starter Anne
  • Start date Start date
A

Anne

I'm trying to evaluate a data control and return string
expressions based on the control's content. For Long
Integer data types, I first convert the control's value to
a variant data type:

varIncidentType = [cmbIncidentType]

then evaluate it:

strIncidentType = IIf(IsNull(varIncidentType), " and [IT]
like '*' ", " and [IT] = " & CStr([varIncidentType]))

I get the error message "invalid use of null". Can
someone explain why, and how to get around it?

Thanks for your help.
 
Anne said:
I'm trying to evaluate a data control and return string
expressions based on the control's content. For Long
Integer data types, I first convert the control's value to
a variant data type:

varIncidentType = [cmbIncidentType]

then evaluate it:

strIncidentType = IIf(IsNull(varIncidentType), " and [IT]
like '*' ", " and [IT] = " & CStr([varIncidentType]))

I get the error message "invalid use of null". Can
someone explain why, and how to get around it?

Thanks for your help.

Did you see the replies to your original message?

There's no reason to convert a control's value to a variant; it already
is a variant. You're probably getting the error when the third argument
of the IIf() call is evaluated. The VBA IIf() function always evaluates
both possible return values, even though it only returns one of them.

You could drop the assignment to varIncidentType, since it's
unnecessary, and rewrite your expression like this:

strIncidentType = _
IIf(IsNull(varIncidentType), _
" and [IT] like '*' ", _
" and [IT] = " & Me.cmbIncidentType))

The concatenation with the string " and [IT] = " will force the
conversion of cmbIncidentType to a string without your needing to pass
it to CStr() anyway.
 
Back
Top