R. Erickson
R. Erickson

Reputation: 1

Access loop through query results using variables from a table

I am new to VBA so I apologize in advance if this seems basic to you experts but I appreciate all of the help I can get.

I have a table containing a column of reference numbers that can grow or shrink weekly. I also have a query pulling back price list data that has changed since last week. The query results vary weekly. What I need to do is assign all of the query results to each reference number and have all of that end up in a make table. For example if there are 10 reference numbers and the query result is 10 rows then 100 lines would be added to the table (adding the reference number to the beginning of each row). This sounds like some sort of loop but your the experts, not me.

Thanks in advance!

Upvotes: 0

Views: 131

Answers (1)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112279

You can solve it with a cross join. In a cross join you join two tables without specifying a join clause. Such a query returns all possible combinations of rows of the two tables (this is called a Cartesian product)

SELECT col_a, col_b INTO newTable
FROM table_a, table_b

If table_a contains 10 rows and table_b contains 5 rows, this returns 50 rows.

Upvotes: 1

Related Questions