Validacion Importacion Datos
Ante todo reciban mis cordiales saludos. Necesito validar la importación de datos, que cuando ejecute el código, y no encuentre la Tabla RE1, ya no me muestre mensaje de error, si existe que exporte los datos.
Dim Fila&, filainicio&, ultimafila$, columnacampo As Byte
Dim Query As String
Dim row As Double
Dim rstdata() As Variant
Set cn = New ADODB.Connection
With cn
.provider = "microsoft.jet.oledb.4.0"
.ConnectionString = "Data Source=C:\BD_Produccion\RE2009M2.mdb"
.Open
End With
Set rst = New ADODB.Recordset
Query = "Select FechaRemito,CodAsociado,Cliente,NOMAR1,NOMAR2,NOMAR3,NOMCE1,NOMCE2,NOMAG1,NOMAD1,NOMAD2,RAR1,RAR2,RAR3,RCE1,RCE2,RAG1,RAD1,RAD2,M3Real,Anulado from RE1"
With rst
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open Query, cn, , , adCmdText
End With
rstdata = rst.GetRows
row = ActiveSheet.Range("A65536").End(xlUp).row
filainicio& = 2
For Fila& = 1 To UBound(rstdata, 2) + 1
For columnacampo = 1 To 21
If Not IsNull(rstdata(columnacampo - 1, Fila& - 1)) Then
Cells(filainicio&, columnacampo) = rstdata(columnacampo - 1, Fila& - 1)
End If
Next columnacampo
Cells(filainicio&, 1).Offset(1, 0).Select
filainicio& = filainicio& + 1
Next Fila&
rst.Close
cn.Close
Set rst = Nothing
Set cn = Nothing
Dim Fila&, filainicio&, ultimafila$, columnacampo As Byte
Dim Query As String
Dim row As Double
Dim rstdata() As Variant
Set cn = New ADODB.Connection
With cn
.provider = "microsoft.jet.oledb.4.0"
.ConnectionString = "Data Source=C:\BD_Produccion\RE2009M2.mdb"
.Open
End With
Set rst = New ADODB.Recordset
Query = "Select FechaRemito,CodAsociado,Cliente,NOMAR1,NOMAR2,NOMAR3,NOMCE1,NOMCE2,NOMAG1,NOMAD1,NOMAD2,RAR1,RAR2,RAR3,RCE1,RCE2,RAG1,RAD1,RAD2,M3Real,Anulado from RE1"
With rst
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open Query, cn, , , adCmdText
End With
rstdata = rst.GetRows
row = ActiveSheet.Range("A65536").End(xlUp).row
filainicio& = 2
For Fila& = 1 To UBound(rstdata, 2) + 1
For columnacampo = 1 To 21
If Not IsNull(rstdata(columnacampo - 1, Fila& - 1)) Then
Cells(filainicio&, columnacampo) = rstdata(columnacampo - 1, Fila& - 1)
End If
Next columnacampo
Cells(filainicio&, 1).Offset(1, 0).Select
filainicio& = filainicio& + 1
Next Fila&
rst.Close
cn.Close
Set rst = Nothing
Set cn = Nothing
1 respuesta
Respuesta de inforvago