Link to home
Start Free TrialLog in
Avatar of agzis
agzis

asked on

IsNull function error

When I call function IsNull against ADO recordset values I'll receive an error that function IsNull should support array datatype. Why this happened? Thanks.
Avatar of mdougan
mdougan
Flag of United States of America image

Can you show the code snippit that is giving you this error as well as the data type of the column that it is blowing up on?
Avatar of agzis
agzis

ASKER

      Dim i, j As Integer
       'i-col;j-row
       j = 1: i = 0
       
       If Not Reds.EOF Then Reds.MoveFirst
                     
       While Not Reds.EOF
           If SSheet.Rows <= j Then
              SSheet.Rows = SSheet.Rows + 1
           End If
       
           SSheet.Row = j
           For i = 0 To (Reds.Fields.Count - 1)
               SSheet.Col = i
               If IsNull(Reds(i)) Then    
                  SSheet.Text = ""
               Else
                  SSheet.Text = Trim(Reds(i))
               End If
           Next i
           Reds.MoveNext
           j = j + 1
       Wend
ASKER CERTIFIED SOLUTION
Avatar of mdougan
mdougan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Function NullText(Text As Variant) As String
    If IsNull(Text) Then
        NullText = vbNullString
    Else
        NullText = Text
    End If
End Function



SSheet.Text = NullText(trim(Reds(i))

Another option is not to use isnull, a faster way that I've found is as follows
variable = rscordset.fields("fieldname") & ""
This will never pop up the Invalid use of null error.