Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/06/2013, 07:39
maialenlopez
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años, 1 mes
Puntos: 7
Ejecutar sentencia insert en VBA Excel

Hola,

No sabia donde meter este tema pero necesito vuestra ayuda.

No se como ejectura la sentencia insert que tengo en vba excel. Escribo lo que tengo para que me echéis una mano.

Código vba Excel:
Ver original
  1. Public conn As New ADODB.Connection
  2. Public tabla As New ADODB.Recordset
  3. Public comando As New ADODB.Command
  4.  
  5. Private Sub Guardar_Click()
  6.     ' Leer datos de las celdas necesarias de la hoja Empleados hydro
  7.    
  8.     Dim fila, columna, cont As Integer
  9.     Dim codEmpleado, operario, codSeccionRRHH, di, linea, sublinea, seccion, seccionDes As String
  10.     fila = Cells(Rows.Count, 4).End(xlUp).Row 'cuenta la cantidad de filas que tiene el excel
  11.    
  12.     conn.Open "DSN=horas"
  13.     If conn.State = 1 Then
  14.         'MsgBox "conexion"
  15.         'MsgBox fila
  16.         For cont = 4 To fila
  17.             codEmpleado = Cells(cont, 4).Value
  18.             operario = Cells(cont, 5).Value
  19.             codSeccionRRHH = Cells(cont, 6).Value
  20.             di = Cells(cont, 8).Value
  21.             linea = Cells(cont, 9).Value
  22.             sublinea = Cells(cont, 10).Value
  23.             seccion = Cells(cont, 11).Value
  24.             seccionDes = Cells(cont, 12).Value
  25.             Sql = "INSERT INTO horas.operario(CodEmpleado, Operario, CodSeccionRRHH, DI, Linea, SubLinea, Seccion, SeccionDes)" & _
  26.                     " VALUES(' " & codEmpleado & " ',' " & operario & " ',' " & codSeccionRRHH & " ',' " & di & " ',' " & linea & " '" & _
  27.                     ",' " & sublinea & " ',' " & seccion & " ',' " & seccionDes & " ')"
  28.  
  29.              [B]'NECESITO SABER COMO EJECUTAR LA QUERY DEL INSERT[/B]
  30.            
  31.         Next
  32.         conn.Close
  33.     Else
  34.         MsgBox "error en la conexion"
  35.     End If
  36. End Sub

__________________
Gracias por todo;

Un saludo