检查RS中的Null值

时间:2015-10-06 07:26:55

标签: sql vba excel-vba null excel

我有以下代码效果很好,但是我想在DWHS宏中添加一些内容来检查'RS'是否返回Null的值。请参阅下面的代码。

Sub ROW31()
Application.ScreenUpdating = False
AltRight_Sub
With ProcImpReview
Dim LASTCOL As Long, DT As String
SQLSTR = ""
LASTCOL = .Range("IV6").End(xlToLeft).Column
    For I = 27 To LASTCOL
    DT = Replace(.Cells(6, I), "/", "-")
    Debug.Print DT
        SQLSTR = "select sum(POVal) FROM IESA_DWHS.dbo.vw_AN_Purch_BKB_010_Sources vw_AN_Purch_BKB_010_Sources " _
                    & " where Upper(Plant) =  upper(('" & .Cells(5, I).Value & "'))  AND  Dt between convert(datetime,'" & DT & "',103) and getdate()-7 and Upper(MatCat) = 'CODED' "
        Debug.Print SQLSTR

            Set RNG = .Cells(31, I)
        SQL_DWHS
    Next I
End With
SQLSTR = ""
AltRight_Sub
Application.ScreenUpdating = True
End Sub

    Sub SQL_DWHS()
        Dim rs As Object
        Dim iCols As Integer
        Set rs = CreateObject("ADODB.Recordset")
        On Error GoTo ERR

            CONNECT_TO_DWHS
            rs.Open SQLSTR, PERSONALDBCONT
            RNG.CopyFromRecordset rs
            End If
            CLOSE_CONNECTION_TO_SQL

            Exit Sub

  `ERR:`
        CLOSE_CONNECTION_TO_SQL
        MsgBox "There was an error"
        End
 End Sub

0 个答案:

没有答案