2

I can't check if an imported value from SQL to Excel is Null. In debug mode I can se that the assigned value is Null, i.e. not the string "Null". Have tried is Nothing as in my code example, but also isEmpty and = "Null".

It's the line If dbList(2) Is Nothing Then in the code below that I'm having trouble with.

How can I check if the recordset is Null?

...
Dim CmdSP As New ADODB.Command
CmdSP.CommandType = adCmdText
CmdSP.CommandText = "SELECT FundName, FundId, SRL.Comment FROM XXX SRL ON XXX = XXX ORDER BY FundName ASC"

CmdSP.ActiveConnection = dbConn

Dim dbList As ADODB.Recordset
Set dbList = CmdSP.Execute

Dim row As Integer
row = 1
While Not dbList.EOF
    DataStorage.Range("dsFundsTopLeft")(row, 2) = dbList(0)
    DataStorage.Range("dsFundsTopLeft")(row, 3) = dbList(1)
    If dbList(2) Is Nothing Then
        DataStorage.Range("dsFundsTopLeft")(row, 4) = "No rating"
    Else
        DataStorage.Range("dsFundsTopLeft")(row, 4) = dbList(2)
    End If
    dbList.MoveNext
    row = row + 1
Wend
...
1
  • Before If dbList(2) Is Nothing Then put a Debug.Print TypeName(dbList(2)) - what is the output? Commented Jun 1, 2017 at 11:25

1 Answer 1

5

Try function isNull

If isNull(dbList(2)) Then
Sign up to request clarification or add additional context in comments.

1 Comment

Feeling stupid now, but the function was not valid when i tried it before. Must have spelled it wrong!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.