Is there any method to execute a batch update with multiple values for single column of Sharepoint list by VBA ?
In the case of appling a batch update with single value for single column to multiple rows, I’ve got that the following code is suitable to do this with good performance.
My past post
Sub SPListUpdate_single_value_multiple_rows()
Const ServerUrl As String = "https://contoso.sharepoint.com/sites/ABC/"
Const ListName As String = "{e5r6t7h8-3d0e-4890-8111-3531bde50f4k}" 'List GUID
Dim Conn As New ADODB.Connection
Dim Sql As String
Dim Batch_size as Integer
Dim Target_rows as String
With Conn ' Open the connection
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;" & _
"DATABASE=" & ServerUrl & ";" & _
"LIST=" & ListName & ";"
.Open
End With
Target_rows = ""
Batch_size = 50
For i = 1 to 999
If (i Mod Batch_size) = 0 OR i = 999 Then
Target_rows = Target_rows & i
Sql = "update [" & ListName & "] set [Col] = 'A' where [Title] in (" & Target_rows & ")"
Conn.Execute Sql
Target_rows = ""
Else
Target_rows = Target_rows & i & ","
End if
Next
End Sub
I wonder if there is a SQL command for VBA that can execute the update to the right side table at one time.
enter image description here
I tried the following SQL (MySQL?) commands but those are not available for VBA (Microsoft ActiveX Data Objects 6.1 Library).
INSERT INTO ListName (Title, Col) VALUES (1,'A'),(2,'B'),(3,'C'),... ON DUPLICATE KEY UPDATE Col = VALUES(Col)
UPDATE ListName SET Col = ELT(FIELD(Title,1,2,3,...),'A','B','C',...) WHERE Title IN (1,2,3,...)
KK0414 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.