I am adding several records to a sharepoint list programmatically using to save time over using a form on the sharepoint as I sometimes have to add up to 50 entries at any given time. It was working fine, and then the macro was shared with other people in the region to use as well, and once that was done it's no longer working. I get the Row handle referred to a deleted row or a row marked for deletion error once it gets to rst.AddNew. I can get the recordset and display it all, and it matches with what is showing in the sharepoint list, so I'm not entirely sure why it has suddenly stopped working. I know looping through everything is not the most efficient way of doing it and would be better to write it all to an array but I was in a time crunch and brute force was easier to write in the moment.
Sub FRC_Upload()
Dim Connect As ADODB.Connection
Dim rst As ADODB.Recordset
Dim mySQL As String
Dim LastRow As Long
Dim MyWorkbook As Workbook
Set MyWorkbook = Workbooks("FRC Upload.xlsm")
LastRow = MyWorkbook.Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
Set Connect = New ADODB.Connection
Set rst = New ADODB.Recordset
mySQL = "SELECT * FROM [FRC];"
With Connect
.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;DATABASE=URL for my sharepoint list;"
.Open
End With
rst.Open mySQL, Connect, adOpenDynamic, adLockOptimistic
For i = 2 To LastRow
rst.AddNew
rst.Fields("Title") = MyWorkbook.Sheets("Data").Range("A" & i)
rst.Fields("MA") = MyWorkbook.Sheets("Data").Range("B" & i)
rst.Fields("ScheduleDate") = MyWorkbook.Sheets("Data").Range("C" & i)
rst.Fields("AccountNumber") = MyWorkbook.Sheets("Data").Range("D" & i)
rst.Fields("WorkorderNumber") = MyWorkbook.Sheets("Data").Range("E" & i)
rst.Fields("WorkOrderType") = MyWorkbook.Sheets("Data").Range("F" & i)
rst.Fields("RescheduleClassification") = MyWorkbook.Sheets("Data").Range("G" & i)
rst.Fields("Comments") = MyWorkbook.Sheets("Data").Range("H" & i)
Next
rst.Update
If CBool(rst.State And adStateOpen) = True Then rst.Close
If CBool(Connect.State And adStateOpen) = True Then Connect.Close
End Sub