View Full Version : What is invalid use of Null??


kwokv616
12-14-2008, 09:50 PM
When I run this code it says "Invalid use of Null", but all my vairables have values...i dont understand what it has got to do with Null...=(

If tmpyr = "Y0" Or bus_type = "FB" Then
r = 0
Else
r = Max(0, DLookup(tmpyr, "CSV_" & bus_type, "Age=" & tmpcnt)) * (1 - fac) + (DLookup(tmpyr2, "CSV_" & bus_type, "Age=" & tmpcnt) + coupon) * fac
End If

Banana
12-14-2008, 09:55 PM
If you happen to be referencing a form control or a field in table:

The issue is that controls and fields (within a table, that is) can hold a Null value but VBA variables cannot so we have to manage for this cognitive dissonance.

There are various ways to do this but Nz function is what you may want to use for most case; it's a function that converts a null value into something, zero by default:

Nz(AbadTextBoxValue) will always return 0 whenever the textbox named "AbadTextBoxValue" contains a null value. You can also add default:

Nz(AbadTextBoxValue, "") to return empty string instead of zero.

HTH.

kwokv616
12-14-2008, 09:58 PM
Thank you very much I'll give it a value of Zero for Nulls!