I have opened my recordset rs with adLockOptimistic which set LockType to 3. However after I Set rs = cn.Execute(strSQL) which executes my SQL string, the LockType got reset to 1, which is read-only and I cannot do an rs.AddNew to the recordset.
Code:
<tbody>
</tbody>
Code:
Set rs = CreateObject("ADODB.Recordset") rs.CursorLocation = adUseServer rs.Open Source:="Customer", _ ActiveConnection:=cn, _ CursorType:=adOpenDynamic, _ LockType:=adLockOptimistic, _ Options:=adCmdTable Dim strSQL As String 'New CustId Range("A2:A100").Select For Each id In Selection NewCustId = id.Value If id.Value <> "" Then strSQL = "SELECT * FROM Customer " & _ "WHERE CustId = '" & NewId & "' " & ";" Debug.Print "LT Before:", rs.LockType Set rs = cn.Execute(strSQL) Debug.Print "LT After:", rs.LockType If (rs.BOF And rs.EOF) Then rs.AddNew rs.Fields("CustomerID").Value = CustId rs.Fields("Addr").Value = id.Offset(0, 1).Value ... more customer info rs.Update Else Debug.Print "Already existed: ", id.Value End If End If Next id |
Using an Execute on my connection, how do I do .AddNew ... .Update on the recordset - make it not for read-only. Please help! |
<tbody>
</tbody>