Hi ctdak,
"Order of an Access query"
1) Join
2) Where
3) Select
Actually, I would have thought it should have
worked if you just leave off the "tablename"
before [HistAccountNo] in the subquery
(and just *not* work if you used
"tblHistory.HistAccountNo")
"(SELECT [HistAccountNo]" & _
If you are still getting error, then you may
have to bite the bullet and type out your "*"
explicitly.
This is what I would do in your situation
(you certainly don't have to follow this advise)
I would create the subquery in query designer
saving as "SummaryQry," including giving tbl_History
an alias of "SubQry."
Then I would bring tbl_History and "SummaryQry"
into another query design. I would give tblHistory
an alias of DetailQry and join the two on HistAccountNo.
Then I would double-click on top of DetailQry table
so all fields are selected, then drag-and-drop selection
down to Field row, then set Criteria row under
..[HistReceiptDate], [HistTaxDed], [HistFundNo].
The point being to make sure this works, plus leading
to the full SQL will end up using in code.
So...if this works, then I would go back to "SummaryQry"
design and copy SQL. Then go to SQL view in the second
query and paste in the "SummaryQry-SQL" in place of
"SummaryQry" in the Select clause (wrapping in parentheses
and giving subquery alias of "SummaryQry").
Then if this works, I would edit this SQL so get only
so many chars per line, then copy and paste in code
and tidy up with "&'s and _".
That's just what I'd do, you are welcome to disregard.
If you start a new thread, I will keep out of it, so you
can get advice from someone who may know better
than me (I regret now that I responded to your other
thread).
Good luck,
Gary Walter
Gary Walter said:
:
<snip>
Here's what I have:
Me.RecordSource = "SELECT * FROM [tbl_History] AS DetailQry " & _
"INNER JOIN " & _
"(SELECT [tbl_History].[HistAccountNo]" & _
" FROM [tbl_History] AS SubQry" & _
" WHERE SubQry.[HistReceiptDate]" & _
" BETWEEN #06/01/2003# AND #04/30/2004# AND" & _
" SubQry.[HistTaxDed] = TRUE AND" & _
" SubQry.[HistFundNo] = 4282" & _
" GROUP BY SubQry.[HistAccountNo]" & _
" HAVING SUM(SubQry.[HistAmt]) >= 1000) AS SummaryQry " & _
"ON DetailQry.[HistAccountNo] = SummaryQry.[HistAccountNo] " & _
"WHERE DetailQry.[HistReceiptDate] " & _
"BETWEEN #06/01/2003# AND #04/30/2004# AND " & _
"DetailQry.[HistTaxDed] = TRUE AND " & _
"DetailQry.[HistFundNo] = 4282"
I don't know if I'm using the "AS" alias names correctly and so far I am getting an
error message: "The specified field 'HistAccountNo' could refer to more than one
table listed in the FROM clause of your SQL statement."
Hi ctdak,
Thank you for the update.
You probably found it, but I believe you
just need to change "line 3" above to:
"(SELECT SubQry.[HistAccountNo]" & _
I believe that was it.
Good luck,
Gary Walter
Gary,
Unfortunately, that didn't fix it. I get the same error still.
I don't understand how you can put SubQry in line 3 when it isn't defined until line 4.
Any other ideas on the error?
ctdak