Link to home
Start Free TrialLog in
Avatar of ktsCatalyst
ktsCatalyst

asked on

How do I create append query with looping functionality

I am working with Access 2007 and trying to create an Append Query with a loop to add records that is dependent upon one of the fields in the Select.  One of the fields, named "OCCURS"  in table1 contains the number of records that needs to be created table2.
For example: if "OCCURS" = 4, then 4 records should be added in table2.  
 
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Can you present a specific example with some sample data?

For example, ...show us what you have, then show us what you need to result to be.
Oh, and Welcome to Experts-Exchange!

;-)

Jeff
Hello ktsCatalyst,

No need to loop.  Instead, create a new table, tblNumbers, with a single column, Number, data type Long.

Populate that table with number from, say, 1-10.  Now, your append query becomes something like this...

INSERT INTO table2 (FieldX, FieldY, FieldZ)
SELECT t1.FieldA, t1.FieldB, t1.FieldC
FROM table1 t1 INNER JOIN
      tblNumbers n ON t1.Occurs >= n.Number

Regards,

Patrick
Avatar of ktsCatalyst
ktsCatalyst

ASKER

Here's what I'm trying to do:

Table1
  PartNo     (A1002C)
  PartDesc   (Cover)
  Qty           (5)
  Occurs     (5)

Table2
  PartNo
  SerialNo

Read records in Table1. In this example, Occurs = 5; Create 5 entries in =Table2
ktsCatalyst,

And how is the serial number determined?

Regards,

Patrick
Patrick,
The serial number will be updated on a form.  For the purposes of this example, this field will be left blank.
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
matthewspatrick,
this is exactly what I needed.  thanks for your help and quick response.