Saludos Profesor Sergio, de ante mano gracias por responder, realice lo que me sugirió coloque el código donde me indicó, sin embargo me sigue arrojando el mismo error.
' Restaurar formato de fuente
With wsHistorico.Rows("2:2").Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
' Incrementar automáticamente el número de recibo
wsRecibo.Range("J2").Value = wsRecibo.Range("J2").Value + 1
'Corrección de Error en impresión
Application.Wait (Now + TimeValue("0:00:01"))
' Imprimir
wsRecibo.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
Por
dorgelis, · publicado
Hola gente soy nuevo y estoy tratando de adaptar un programa vba a mi necesidad pero al momento de ejecutarlo me da el erro 3709
Option Explicit
Public CN As ADODB.Connection
Dim Cod_Prod, Nombre, Existencia
Dim Fila, Final As Integer
Function Connect(Server As String, User As String, Pass As String, Database As String) As Boolean
Set CN = New ADODB.Connection
On Error Resume Next
With CN
.ConnectionString = "Provider=SQLOLEDB.1;" & _
"Password=" & Pass & ";" & _
"Persist Security Info=True;" & _
"User ID=" & User & ";" & _
"Initial Catalog=" & Database & ";" & _
"Data Source=" & Server
.Open
End With
If CN.State = 0 Then
Connect = False
Else
Connect = True
End If
End Function
Function Query()
Dim SQL As String
Dim RS As ADODB.Recordset
Dim Field As ADODB.Field
Dim Col As Long
Set RS = New ADODB.Recordset
Final = GetUltimoR(Hoja1)
For Fila = 2 To Final
Cod_Prod = Hoja1.Cells(Fila, 2)
Nombre = Hoja1.Cells(Fila, 3)
Existencia = Hoja1.Cells(Fila, 4)
SQL = "insert into productos values('" & Cod_Prod & "','" & Nombre & "'," & Existencia & ");"
RS.Open SQL, CN el error me lo marca en esta linea
Next
RS.Open "SELECT * FROM PRODUCTOS", CN
If RS.State Then
Col = 1
For Each Field In RS.Fields
Cells(1, Col) = Field.Name
Col = Col + 1
Next Field
Cells(2, 1).CopyFromRecordset RS
Set RS = Nothing
End If