Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Record Iterations - SQL RST to Access RST

Status
Not open for further replies.

jaycast

Programmer
Nov 28, 2001
42
US
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!!!


 
In your For..Next loop you are only doing a MoveNext on rs2 - do it on rs1 at the same time. You also need to set rs1 to Nothing at the end, rather than rs2 twice! [smile]

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I knew it was going to be something as simple as that. I have been staring at this for about 1 1/2 hours trying to see what I missed...I guess all I needed was a second pair of eyes to point out the obvious.

Thanks John!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top