我正在尝试自动填充SharePoint列表,但出现“行句柄无效”错误。我的代码:
Sub test()
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQLstr As String
SQLstr = "SELECT * FROM [DB];"
With cnt
.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"WSS;" & _
"IMEX=0;" & _
"RetrieveIds=Yes;" & _
"DATABASE=" & URL & ";" & _
"LIST=" & ListID & ";"
.Open
End With
rst.Open SQLstr, cnt, adOpenDynamic, adLockOptimistic
With rst
.AddNew
.Fields(1) = ws.Cells(1, 1).Value
.Fields(4) = ws.Cells(1, 2).Value
.Fields(7) = ws.Cells(1, 3).Value
.Update
End With
End Sub
错误在.Update
行上弹出。我创建了一个全新的SP列表,该代码运行正常。但是由于某种原因,它不适用于我需要使用的列表。另外,在两个列表上,我都可以使用rst.Find
方法并成功更新现有记录。为什么会出现此错误?