What is invalid use of Null??

kwokv616

Registered User.
Local time
Today, 00:33
Joined
Nov 10, 2008
Messages
46
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
 
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.
 
Thank you very much I'll give it a value of Zero for Nulls!
 

Users who are viewing this thread

Back
Top Bottom