I have asked a recent question about using SQL to update SharePoint Lists in VBA/ADO, and got a good answer, which I have managed to get working. My current code is as follows:
Public Sub Update_some_list()
Dim ListID As String, SharePointSite As String
ListID = "Test_Staff"
SharePointSite = "https://companyname.sharepoint.com/sites/proc2126"
Dim c As New ADODB.Connection
c.Open "Provider=Microsoft.ACE.OLEDB.12.0;WSS;DATABASE=" & SharePointSite & ";LIST=" & ListID
Dim SQL As String
SQL = "UPDATE [Test_Staff] SET [StaffName]='ChrisTest' WHERE [UserName]='melvilc';"
c.Execute SQL
c.Close ' I want to eliminate the requirement to close the connection, then re-open with a different list
ListID = "Duplicate_Test"
c.Open "Provider=Microsoft.ACE.OLEDB.12.0;WSS;DATABASE=" & SharePointSite & ";LIST=" & ListID
SQL = "UPDATE [Duplicate_Test] SET [Three]='ChrisTest' WHERE [Four]='Deleted';"
c.Execute SQL
End Sub
This works well enough. But I would ideally like a way to update more than one single SharePoint list within the same connection. My existing code is based around MS Access-compatible databases, and I would use a single database connection before executing SQL statements which specify table names. However when I try this with SharePoint Lists, I get an error message "No value given for one or more required parameters".
That's why, in the above code, I need to close the "Test_Staff" connection and open a different "Duplicate_Test" connection.
But is there any way to use the same general connection to the SharePoint site, and use SQL to specify exactly which list to update?