I am having a problem updating records into a MySQL database with the
ADO API and ODBC provider. The moment I give a rs.Update method excel
crashes.
I am submitting my code with several lines deleted but included lines
which have to deal with the connection and the updating of the
records.
Sub RegenerateRecordSet(c As String, rngNm As Range, q As String)
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs_Name As ADODB.recordset
On Error Resume Next
Set cn = New ADODB.Connection
cn.ConnectionString = c
cn.Open
If Err.Number <> 0 Then
MsgBox "Connection error: " & Err.Description
Exit Sub
End If
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = cn
cmd.CommandText = q
cmd.CommandType = adCmdText
Set rs_Name = New ADODB.recordset
Set rs_Name.Source = cmd
rs_Name.CursorLocation = adUseClient
rs_Name.LockType = adLockOptimistic
rs_Name.CursorType = adOpenDynamic
cn.Errors.Clear
rs_Name.Open
'Here I try to change a value in the recorset
rs_Name.Fields(1).Value = 1.00
'I verified that the value has changed thru the immediate window
' ?rs_name.Fields(1).value
' This gives me the result 1.00
rs_Name.Update
'The moment it executes this method it crashes.
rs_Name.Close
cn.Close
End Sub