ADODB.Connection-- aqui se detiene mi macro? porque amigos?

11/07/2004 - 00:47 por Javier | Informe spam
Sub ADOFromExcelToAccess()
' exports data from the active worksheet to a table in an
Access database
' this procedure must be edited before use
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As
Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Base\Base.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "Ventas Totales", cn, adOpenKeyset,
adLockOptimistic, adCmdTable
' all records in a table
r = 5 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("REM_FOLIO") = Range("A" & r).Value
.Fields("REM_prefijo") = Range("b" & r).Value
.Fields("LIQ_FOLIO") = Range("c" & r).Value
.Fields("REM_ESTATUS") = Range("d" & r).Value
.Fields("REM_FECHA") = Range("f" & r).Value
.Fields("CLI_CLAVE") = Range("g" & r).Value
.Fields("REMCEDIS") = Range("h" & r).Value
.Fields("REM_TIPO_PAGO") = Range("i" & r).Value
.Fields("SUC_CLAVE") = Range("j" & r).Value
.Fields("PRO_CLAVE") = Range("K" & r).Value
.Fields("SUM(RD.DREM_TOTAL)") = Range("L" &
r).Value
.Fields("SUM(RD.DREM_CANTIDAD)") = Range("M" &
r).Value
.Fields("SUM(RD.DREM_SUBTOTAL)") = Range("N" &
r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
 

Leer las respuestas

#1 Javier
11/07/2004 - 20:53 | Informe spam
amigos ya encontre elprblema es una libreria que hace
falta cargar es microsoft activeXdata objets 2.1
Saludos
Sub ADOFromExcelToAccess()
' exports data from the active worksheet to a table in an
Access database
' this procedure must be edited before use
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As
Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Base\Base.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "Ventas Totales", cn, adOpenKeyset,
adLockOptimistic, adCmdTable
' all records in a table
r = 5 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("REM_FOLIO") = Range("A" & r).Value
.Fields("REM_prefijo") = Range("b" & r).Value
.Fields("LIQ_FOLIO") = Range("c" & r).Value
.Fields("REM_ESTATUS") = Range("d" & r).Value
.Fields("REM_FECHA") = Range("f" & r).Value
.Fields("CLI_CLAVE") = Range("g" & r).Value
.Fields("REMCEDIS") = Range("h" & r).Value
.Fields("REM_TIPO_PAGO") = Range("i" &


r).Value
.Fields("SUC_CLAVE") = Range("j" & r).Value
.Fields("PRO_CLAVE") = Range("K" & r).Value
.Fields("SUM(RD.DREM_TOTAL)") = Range("L" &
r).Value
.Fields("SUM(RD.DREM_CANTIDAD)") = Range("M"


&
r).Value
.Fields("SUM(RD.DREM_SUBTOTAL)") = Range("N"


&
r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub

.

Preguntas similares