PC Review


Reply
Thread Tools Rate Thread

Creating and looping through a record set.

 
 
Bill
Guest
Posts: n/a
 
      4th Feb 2010
I haven't done any coding for two years and didn't do much of it then but
here is my problem. I have looked though my old access books but am not
having any luck what so ever.

I have a table called "tblInvoice" with three fields "strInvNum",
"strGLAcct", and "dblAmount". The fields strGlAcct and dblAmount may contain
arrays. An example of the data looks like this.

strInvNum strGLAcct dblAmount
556 536~436 50.00~100.15
557 466 30.00
558 536~556~563 1.50~536.00~56.15

I need to then put the records into a table called tblInvoiceDetail as
follows:
strInvNum LineNum strGlAcct dblAmount
556 1 536 50.00
556 2 436 100.15
557 1 446 30.00
558 1 536 1.50
558 2 556 536.00
558 3 563 56.15

Any suggestions on how to do this? I did it years ago but no longer have the
database to copy the code from.

 
Reply With Quote
 
 
 
 
pietlinden@hotmail.com
Guest
Posts: n/a
 
      4th Feb 2010
On Feb 4, 3:20*pm, Bill <B...@discussions.microsoft.com> wrote:
> I haven't done any coding for two years and didn't do much of it then but
> here is my problem. I have looked though my old access books but am not
> having any luck what so ever.
>
> I have a table called "tblInvoice" with three fields "strInvNum",
> "strGLAcct", and "dblAmount". The fields strGlAcct and dblAmount may contain
> arrays. An example of the data looks like this.
>
> strInvNum * strGLAcct * * * * * dblAmount
> 556 * * * * * *536~436 * * * * * *50.00~100.15
> 557 * * * * * *466 * * * * * * * * * 30.00
> 558 * * * * * *536~556~563 * *1.50~536.00~56.15
>
> I need to then put the records into a table called tblInvoiceDetail as
> follows:
> strInvNum * LineNum * strGlAcct * dblAmount
> 556 * * * * * * 1 * * * * * * 536 * * * ** * *50.00
> 556 * * * * * * 2 * * * * * * 436 * * * ** *100.15 * * *
> 557 * * * * * * 1 * * * * * * 446 * * * ** * *30.00
> 558 * * * * * * 1 * * * * * * 536 * * * ** * * *1.50
> 558 * * * * * * 2 * * * * * * 556 * * * ** * 536.00 * *
> 558 * * * * * * 3 * * * * * * 563 * * * ** * * 56.15
>
> Any suggestions on how to do this? I did it years ago but no longer have the
> database to copy the code from.


Use SPLIT() to break the repeating values out. You'll need to do it
for both GIAccount and Amount. Since they should have the same number
of values, you could use a single counter variable to loop through
them.

dim varGIAccount as Variant, varAmount as Variant
'process outer loop here...
dim rsDest as dao.recordset
rsDest.OpenRecordset("DestTable",dbAppendOnly)
rsSrc.OpenRecordset("SrcTable",dbopenForwardOnly)
do until rsSrc.EOF
varGIAccount = Split(rsSrc.Fields("strGLAcct"),"~")
varAmount = Split(rsSrc.Fields("dblAmount"),"~")
for i = LBound(varGIAccount) to UBound(varGIAccount)
With rsDest
.addnew
.fields("InvNum") = rsSrc.Fields("strInvNum")
.fields("LineNum") = rsSrc.Fields("LineNum")
.Fields("GIAccount") = varGIAccount(i)
.Fields("Amount") = varAmount(i)
.Update
next i

rsSrc.close
rsDest.close

....totally untested, but that should get you started. Basically, you
split the two repeating fields into arrays, using Split() and then you
loop through the arrays, adding the values to the final table.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping Through All of the Fields in a ADO Record LA Lawyer Microsoft Access Form Coding 6 17th Apr 2010 01:18 PM
Looping and creating sub sums mdrw Microsoft Excel Programming 1 22nd Feb 2006 10:12 AM
Looping and comparing each record... fasanay@yahoo.com Microsoft Access 3 9th Dec 2004 08:05 PM
Looping and comparing each record... fasanay@yahoo.com Microsoft Access Queries 3 21st Oct 2004 08:52 PM
Looping and comparing each record... fasanay@yahoo.com Microsoft Access Forms 1 21st Oct 2004 08:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:50 AM.