I am trying to use the results of another query to use as a criteria for another. In my specific example, I might have four houses that are ‘A’, ‘B’, ‘C’, ‘D’ (the unique values of a field in a table called Homes).
I want to go through another query and say for each house type, what percent of residents (in Residents table) are married, which I want to do by using Count() to count the number for each Home type.
Do I need to loop through the results using VBA? Asking on a higher level, is there a way to use the results from a query as inputs into another – more than just limit the results of the new query to the results of the prior query?
In semi-pseudo code:
For each (result of previous query) Do New query WHERE field1 = (row of previous query) End Do
What I am trying to ask, is there a way to accomplish this in Access using SQL? Or is this something that has to be done in VBA?
I know that if it can be done in SQL that would be the best performing and best practice, but I’m relatively inexperienced in SQL and online resources aren’t always helpful because Access has it’s own particular flavor of SQL.
Since you are using VBA to run this, you can loop through your recordsets and yes you can use a value from one query in the next query. There are alot of resources out there to help.
Answered By – Taryn
Answer Checked By – Timothy Miller (BugsFixing Admin)