"Invalid use of Null" when using Str () with a Null Recordset field, but Str (Null) works fine

I bang my head against the wall on this one. I looked at some old database reporting code written in VB6 and came across this line (the code moves the data from the "source" database to the reporting database):

rsTarget!VehYear = Trim(Str(rsSource!VehYear))

If rsSource!VehYear- Null, the line above generates an "Invalid Null Usage" error at runtime. If I break the above line and in the Immediate panel, enter the following:

?rsSource!VehYear

He deduces Null. Ok, that makes sense. Then I try to reproduce the error:

?Str(rsSource!VehYear)

I get an "Invalid Null Usage" error.

However, if I enter the following into the Immediate window:

?Str(Null)

. Null.

Trim() Str(), . ?Trim(rsSource!VehYear) Null, ?Trim(Null). .

, : Str(rsSource!VehYear) " Null" , Str(Null) , , rsSource!VehYear Null?


:. Immediate, ( ):

?Str(rsSource!VehYear.Value)

Null. , rsSource!VehYear ADODB.Field, Value , Str Value ( Null). ( " Null" ) , Str Null, Null - , ?

, Str() - , " Null" (- , , " " Null ", , Field).

- , ?

:

?Str(rsSource!VehYear)

" Null" , rsSource!VehYear - Null,

?Str(rsSource!VehYear.Value)

Null.

Trim(rsSource!VehYear) Trim(rsSource!VehYear.Value) Null.

+5
4

Str , Null . , String. Str, Field - , Null . Str , , , , . , , , Null . , MS , Null Str. , Str .

+5

, , IsNull:

rsTarget!VehYear = IIf(IsNull(rsSource!VehYear), 0, rsSource!VehYear)

' 0

+6

vb6-:

rsTarget!VehYear = Trim(Str(rsSource!VehYear & "")) 

& " , .

+1

Nothing (, , vbNull), , Null. :

If (rsSource!VehYear Is Nothing) Then
    ' Null
Else
    ' Not null
End If
0

All Articles