Solved

Loop and combine records from two tables into third table

Posted on 2013-01-17
2
395 Views
Last Modified: 2013-01-17
I have a form with two multi-select list boxes.
1. list box contains months (recordset = tmpInvoiceMth)
2.  list box contains years (recordset = tmpInvoiceYr)

Once the user has chosen their corresponding months and years I would like to loop through both recordsets and add the corresponding Mth-Yr combination into a third recordset (tmpInvoiceMthYr)

EX:  User chooses Jan and Feb from list box 1 and  2012 and 2013 from list box 2
after looping tmpInvoiceMthYr should contain the following records

Jan 2012
Feb 2012
Jan 2013
Feb 2013

Thanks as always for your assistance

~Worcse
0
Comment
Question by:Worcse
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 300 total points
Comment Utility
dim j, i
rs as dao.recordset

set rs=currentdb.openrecordset("tmpInvoiceMthYr")
for each j in me.listMonth.itemsselected

      for each i in me.listYear.itemsselected
            with rs
                 .addnew
                 !MonthYear=me.listMonth.itemdata(j) & " " & me.listYear.itemdata(i)
                 .update
             end with

      next i
next j
0
 

Author Comment

by:Worcse
Comment Utility
Cap - spot on as always
Well done sir...!
Thank you for your assistance.
~Worcse

I have attached the code which is now working for me
tmpInvoiceMthYr.doc
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now