Invalid Use of Null

  • Thread starter Thread starter PJFry
  • Start date Start date
P

PJFry

I am trying to pass a filter value based on a combo box.

If IsNull(Forms!fReporting!cboVendor) Then
vFilter = ""
Else
vFilter = "lngVendorID = '" & Forms!fReporting!cboVendor & "'"
End If

If cboVendor does not have a value, then I want vFilter="", but I keep
getting the null error. How do you get around that?

Thanks!
PJ
 
PJFry said:
I am trying to pass a filter value based on a combo box.

If IsNull(Forms!fReporting!cboVendor) Then
vFilter = ""
Else
vFilter = "lngVendorID = '" & Forms!fReporting!cboVendor & "'"
End If

If cboVendor does not have a value, then I want vFilter="", but I keep
getting the null error. How do you get around that?


Your test for "If IsNull()" should take care of that, if the combo box is
really Null. Where do you get this "null error"? On what line of code?
What exactly are the error message and number?

Where is this code running? Are the quoted lines executed on the form
"fReporting", or elewhere?
 
Hi PJ,

I use the nz function a lot. I seem to recall that I had the same issue you
have that the IsNull function does not work like I expected. So I would write
something like this, assuming that cboVendor cannot be negative:

------------- code start----------
dim vendorID as long
vendorID = Nz(Forms!fReporting!cboVendor, -1)

If vendorID < 0 Then
vFilter = ""
Else
vFilter = "lngVendorID = " & Cstr(vendorID)
End If
------------- code start----------
Also note that I did not include quotation marks around the vendorID as it
seems to a numeric field. If it is a text field you should of course reinsert
them.

Regards,
anlu
 
Back
Top