首页 > 解决方案 > “通过”VBA 附近的语法不正确

问题描述

我收到一个错误

“通过”附近的语法不正确

(可能缺少一些空格逗号?),没有任何进一步的细节。

你能帮我么?

非常感谢贾娜

 Private Sub CommandButton1_Click()
    
    Dim con As ADODB.Connection
    Set con = New ADODB.Connection
    con.Open "Driver={SQL Server};Server=.;Database=P;Uid=ss;Pwd=In;"
    
    
    Dim rng As Range: Set rng = Application.Range("A2:N2")
    Dim row As Range
    For Each row In rng.Rows
        dis = row.Cells(1).Value
        ret = row.Cells(2).Value
        dis_country = row.Cells(3).Value
        ret_country = row.Cells(4).Value
        ph1 = row.Cells(5).Value
        flag = row.Cells(6).Value
        kpi = row.Cells(7).Value
        Group = row.Cells(8).Value
        Value = CDbl(row.Cells(9).Value)
        fiscal_quarter = row.Cells(10).Value
        qtr = CDbl(row.Cells(11).Value)
        week = CDbl(row.Cells(12).Value)
        timestamp = CDbl(row.Cells(13).Value)
        UserID = row.Cells(14).Value
        Sql = "insert into [IMPORT].[tb] values('" & dis & "'," & ret & " ," & dis_country & " ," & ret_country & " ," & ph1 & " ," & flag & " ," & kpi & " ," & Group & " ," & Value & " ," & fiscal_quarter & " ," & qtr & " ," & week & " ," & timestamp & " ," & UserID & ")"
        con.Execute Sql
    Next row
    
        con.Close
        MsgBox "Done"
        
    End Sub

标签: sqlexcelvba

解决方案


推荐阅读