They're exactly the same.
This is the query in the Access SQL view (I copy/pasted from the VBA form to
the SQL view):
SELECT Assets.AssetNo, T.TransType, Assets.User1, Assets.User2,
Assets.[Serial#] FROM Assets LEFT JOIN (SELECT * FROM History WHERE
TranDate >= #1/1/2003# AND TranDate <= #2/1/2003# ) AS T ON Assets.AssetNo
= T.AssetNo WHERE Assets.Purch_Date >= #1/1/2003# And Assets.Purch_Date<=
#2/1/2003# AND T.AssetNo Is Null
_________________________________
This is the code in VBA with the *exact* sql query :
Dim strDocName As String, strSQL As String
Dim datBefore As Date, datAfter As Date
datBefore = Me.BeforeDate.Value
datAfter = Me.AfterDate.Value
strDocName = "AssetsNotInventoriedReport_2"
strSQL = "SELECT Assets.AssetNo, T.TransType, Assets.User1, Assets.User2,
Assets.[Serial#] FROM Assets LEFT JOIN (SELECT * FROM History WHERE
TranDate >= #1/1/2003# AND TranDate <= #2/1/2003# ) AS T ON Assets.AssetNo
= T.AssetNo WHERE Assets.Purch_Date >= #1/1/2003# And Assets.Purch_Date<=
#2/1/2003# AND T.AssetNo Is Null"
DoCmd.OpenReport "AssetsNotInventoriedReport_2", acViewPreview, , strSQL
In the SQL view, it'll bring me the correct recordset. When running through
VBA I'll get the error 3306: "You have written a subquery that can return
more than one field without using the EXISTS reserved word in the main
query's FROM clause. Revise the SELECT statement of the subquery to request
only one field."
Note: While typing the error I did notice that the error tells me that my
subquery should only request only *one* field. But that would mean that the
engine that runs my VBA query is different than the Jet engine that runs my
Access query.
Vaughn
Dirk Goldgar said:
VM said:
I have this query that I built in MS Access that's something like
this: SELECT Assets.AssetNo, T.TransType, Assets.User1, Assets.User2,
Assets.[Serial#],
FROM Assets LEFT JOIN (SELECT * FROM History WHERE TranDate >=
#1/1/2003# AND TranDate <= #2/1/2003# ) AS T ON Assets.AssetNo =
T.AssetNo WHERE Assets.Purch_Date >= #1/1/2003# And
Assets.Purch_Date<= #2/1/2003# AND T.AssetNo Is Null
When I execute it through Acces it'll return a valid recordset.
When I execute it through VBA (the same exact query), it'll return a
run-time error '3306': "You have written a subquery that can return
more than one field without using the EXISTS...."
Is this possible?
Seems odd. Although the query designer will rewrite this query slightly
to conform to its own syntax, the query looks okay to me. I think
you're going to have to post both the exact SQL from the query
designer's SQL View, and the exact VBA code that you run to get this
error.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)