“行句柄无效”错误,Excel,VBA,SharePoint列表自动化

问题描述 投票:0回答:1

我正在尝试自动填充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方法并成功更新现有记录。为什么会出现此错误?

excel vba excel-vba sharepoint
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.