|
初学ADO,想将分表中某个单位的数据写入到总表相应的位置,使用了UPDATE语句,但sSql = "UPDATE [" & TableName & "$] SET 数据=" & sj & "WHERE 单位=" & ID
这一句报错,不知如何修改,向各位老师请教,望得到指点。
Sub 写数()
sj = Sheets("数据分表").Range("b2").Value
ID = Sheets("数据分表").Range("a2").Value
Dim conn As ADODB.Connection
Dim WN As String
Dim TableName As String
Dim sSql As String
WN = "总表.xls"
TableName = "数据总表"
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;" & _
"Extended Properties=Excel 8.0;" & _
"Data Source=" & ThisWorkbook.Path & "\" & WN
conn.Open
If conn.State = adStateOpen Then
sSql = "UPDATE [" & TableName & "$] SET 数据=" & sj & "WHERE 单位=" & ID
conn.Execute sSql
MsgBox "已成功在数据库添加数据!"
conn.Close
End If
Set conn = Nothing
End Sub
|
|