Well... my problem is that I am running a macro in Excel where I take values from cells and insert them into a local MySQL Database using an ADODB connection.
The thing is that this famous error 91 in runtime appears in the line where I send the command to the database (I'm using Workbench to administrate that database). My code is:
Private Sub btnAgregarE1_Click()
Sheets("EMPLEADO").Select
Range("B4").EntireRow.Insert
Range("B4").Value = Me.txtCodigoEmpleadoE1.Value
Range("C4").Value = Me.txtNombreE1.Value
Range("D4").Value = Me.txtFechaE1.Value
Range("E4").Value = Me.txtReferenciaE1.Value
Range("F4").Value = Me.txtDireccionE1.Value
txtCodigoEmpleadoE1.Value = Range("J3").Value
Me.txtNombreE1.Value = Empty
Me.txtFechaE1.Value = Empty
Me.txtReferenciaE1.Value = Empty
Me.txtDireccionE1.Value = Empty
Me.listaEmpleado.RowSource = "tEmpleado"
Me.listaEmpleado.ColumnCount = 5
Dim con As ADODB.Connection
Set con = New ADODB.Connection
con.Open "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=localhost;DATABASE=bdferreteria;USER=PruebaUser;PASSWORD=Passw0rd;"
Dim rng As Range
Set rng = Application.Range("tEMPLEADO")
Dim row As Range
Dim instructsql As String
'instructsql = "Insert into EMPLEADO(Cod_empleado, Nombre, Fecha_inicio, Referencia, Direccion) values ('" & row.Cells(1).Value & "', '" & row.Cells(2).Value & "'," & row.Cells(3).Value & "," & row.Cells(4).Value & "," & row.Cells(5).Value & ")"
con.Execute "Insert into EMPLEADO(Cod_empleado, Nombre, Fecha_inicio, Referencia, Direccion) values ('" & row.Cells(1).Value & "', '" & row.Cells(2).Value & "'," & row.Cells(3).Value & "," & row.Cells(4).Value & "," & row.Cells(5).Value & ")"
con.Close
And the error is in the line:
con.Execute "Insert into EMPLEADO(Cod_empleado, Nombre, Fecha_inicio, Referencia, Direccion) values ('" & row.Cells(1).Value & "', '" & row.Cells(2).Value & "'," & row.Cells(3).Value & "," & row.Cells(4).Value & "," & row.Cells(5).Value & ")"
I've tried to declare and object, then an empty variable, then I created instructsql
as a string and with that try to execute the con.Execute
command, but the error always appears in that specific line no matter what I do.
Any help will be appreciated
Here is the error message: