0

I have a simple script to update sharepoint lists using VBA that's not working.

Option Explicit

Sub add_new_item()

Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset

Dim mySQL As String

Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset

mySQL = "SELECT * FROM [Test];"

With cnt
        .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;DATABASE=https://share.amazon.com/sites;List={9E4AEE54-AF41-430B-8780-8BD778A1A226};"
        .Open
End With

rst.Open mySQL, cnt, adOpenDynamic, adLockBatchOptimistic

rst.AddNew
        rst!Task_ID = Sheets("Sheet2").Range("C3").Value
rst.Update

'To close the connection and clean the memory

If CBool(rst.State And adStateOpen) = True Then rst.Close
Set rst = Nothing
If CBool(cnt.State And adStateOpen) = True Then cnt.Close
Set cnt = Nothing

End Sub

When i try to run it, I get the following error:

enter image description here

And whilst debugging, it happens on this line:

rst.Open mySQL, cnt, adOpenDynamic, adLockBatchOptimistic

I believe that I might have maybe written the wrong connection string?

This is the link to the list: https://share.amazon.com/sites/IPV/Lists/Test/AllItems.aspx This is the list id: List={9E4AEE54-AF41-430B-8780-8BD778A1A226}

2
  • If the connection string was wrong I would have expected it to fail on the conn.open. Add line Debug.Print conn.DefaultDatabase before rst.open ...' Commented Mar 30, 2021 at 16:05
  • Sorry for repeating the comment, but i wanted to see if maybe you could help me "as it seems to be due to " Set objWksheet = WksSharePointData " as it states that the variable WksSharePointData is not defined, would you by any chance know what that was due to ? ive been searching everywhere online." Commented Mar 30, 2021 at 18:17

1 Answer 1

0

The error is weird and not sure if it has something to do with the connections. Upon checking the connection string I think that the correct URL should be "https://share.amazon.com/sites/IPV", also the GUID should be getting on the list setting page not on the list display view.

Sign up to request clarification or add additional context in comments.

1 Comment

That was very helpful! thank you very much. Just one quick question about the error, as it seems to be due to " Set objWksheet = WksSharePointData " as it states that the variable WksSharePointData is not defined, would you by any chance know what that was due to ? ive been searching everywhere online.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.