Microsoft Access: Selecting from a query

Why isn’t this working?

I’m toying around with SQL in MS Access. I have a table, called “TransEx.” I have a query that goes:

SELECT DISTINCT F1, F2
FROM TransEx
WHERE F4 = “SPA 200”.

That one works. Then I have another query, that goes:

SELECT F1
FROM Query1

And when I try to run that one, it says Access can’t find the table or query Query1. But there it is right there on my screen. By which I mean, to the right of the “TransEx” tab I see another tab that says “Query1,” which contains that first query I typed up above. “Query2”, meanwhile, is on the tab to the right of “Query1”, and it’s Query2 that claims its neighbor Query1 doesn’t exist…

What obvious thing am I missing here?

Did you save the first query as “Query1”

Access has no way of knowing what “Query1” is unless you save it.
Or did you perhaps name your first query something else?

That was it–I didn’t realize I had to save the query.

Glad you got it fixed

You don’t “have” to save it. You can create a subquery by putting a query within a query like so:

Select F1
FROM (SELECT DISTINCT F1, F2
FROM TransEx
WHERE F4 = “SPA 200”);

Of course it would be a little silly to create such a query in the above case, there are plenty of reasons to use a sub-queries especially when using HAVING and IN clauses.