okay, i see what you're saying now. but unfortunately it's not that easy;
you don't need three separate SQL statements running in VBA, you need one.
as an example, let's say you have qryA as a saved query object in the
database window, and you want to base a SQL statement on the query, in your
code. you could build a SQL string like this, as
strSQL = "SELECT SomeField, SomeOtherField " & _
"FROM qryA " & _
"ORDER BY SomeField;"
easy enough, right? but, as you said, you do NOT have qryA stored as a query
object in the database; instead, you want to also build qryA in the VBA
code. but you can't build and run it as a *separate* SQL string. you have to
replace "qryA" within strSQL with the actual qryA SQL statement. something
along the lines of
strSQL = "SELECT SomeField, SomeOtherField " & _
"FROM (SELECT * FROM SomeTable) As qryA " & _
"ORDER BY SomeField;"
here's where i have to stop. i doubt that the SQL statement above is the
correct syntax, but you can try it - and of course yours will need to be
even more complex, since your qryA SQL statement is based on a qryB SQL
statement. i've used nested SQL statements in the past, but my recent (16
months) experience is with A97, and i can't get nested SQL statements to
work in query objects or in VBA code, for the life of me. so i don't know if
the problem is with me, or some limitation of A97. at any rate, SQL is not
my strong point, so i'm not able to help you further, sorry.
sometimes other developers watch a thread without participating, so maybe
somebody else will step in to help. suggest you give it a day or so; then
start a new thread if necessary - making it clear that you're working with
SQL strings in VBA code, not saved query objects in the database. you can
refer to this thread if you want to, but don't expect others to find and
read this whole thread in order to answer your questions in a new thread.
good luck with it.
hth