I am trying to add data to an Access table using ADO in VB from a SQL recordset. I am able to get the records to add to specified table, populating the same number of records as is the recordcount of the SQL recordset, however, it simply lists the first record over and over. I'm assuming this is a very simple connection or recordset configuration, but I haven't been able to isolate it.
Here is what I have so far:
Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs1 As New ADODB.Recordset, rs2 As New ADODB.Recordset
Dim sql as string
Dim count as integer, x as integer
sql = [Desired SQL String]
cn.Open "FreightInvoices", "sa", ""
With rs1
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open sql, cn
Set .ActiveConnection = Nothing
End With
Set cn = Nothing
cn.Open "EDIDOCS", "sa", ""
With rs2
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "tblFedExInvoiceBreakdown", cn
End With
rs1.MoveFirst
count = rs1.RecordCount
x = 1
For x = 1 To count
rs2.AddNew
rs2("InvoiceNumber"
= rs1("InvoiceNumber"
rs2("TransDate"
= rs1("TransDate"
rs2("InvoiceDate"
= rs1("InvoiceDate"
rs2("NetAmtDue"
= rs1("NetAmtDue"
rs2("ChargeAmount"
= rs1("ChargeSum"
rs2("ShipDate"
= rs1("ShipDate"
rs2("TradingPartnerName"
= rs1("TradingPartnerName"
rs2.Update
rs2.MoveNext
Next x
Set cn = Nothing
Set rs2 = Nothing
Set rs2 = Nothing
Can someone point out my (hopefully) simple mistake?
Thanks in advance!!!
Here is what I have so far:
Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs1 As New ADODB.Recordset, rs2 As New ADODB.Recordset
Dim sql as string
Dim count as integer, x as integer
sql = [Desired SQL String]
cn.Open "FreightInvoices", "sa", ""
With rs1
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open sql, cn
Set .ActiveConnection = Nothing
End With
Set cn = Nothing
cn.Open "EDIDOCS", "sa", ""
With rs2
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "tblFedExInvoiceBreakdown", cn
End With
rs1.MoveFirst
count = rs1.RecordCount
x = 1
For x = 1 To count
rs2.AddNew
rs2("InvoiceNumber"
rs2("TransDate"
rs2("InvoiceDate"
rs2("NetAmtDue"
rs2("ChargeAmount"
rs2("ShipDate"
rs2("TradingPartnerName"
rs2.Update
rs2.MoveNext
Next x
Set cn = Nothing
Set rs2 = Nothing
Set rs2 = Nothing
Can someone point out my (hopefully) simple mistake?
Thanks in advance!!!