Link to home
Start Free TrialLog in
Avatar of Dalexan
DalexanFlag for Afghanistan

asked on

Sub Select in MS Access 2002 not working

I am trying to create a sub select in access 2002 to work in a form.  This is the code I am currently using, but access keeps telling me the sub select is invalid.

SELECT TblMediaExport.ord_confirm_date
FROM ([SELECT Table_and_Query_Lookup.TblMediaExport FROM Table_and_Query_Lookup WHERE Active = True] AS TblMediaExport)
WHERE ([TblMediaExport].[ord_id])>0;
Avatar of morpheus30
morpheus30

SELECT TblMediaExport.ord_confirm_date, ([SELECT Table_and_Query_Lookup.TblMediaExport FROM Table_and_Query_Lookup WHERE Active = True]) AS TblMediaExport
FROM TblMediaExport
WHERE ([TblMediaExport].[ord_id])>0;
Avatar of jadedata
That subselect has no field outputs unless tblMediaExport is a field name, which still leaves that it is not the field used in the main select...

There is bracketing in the subselect that I'm not sure belongs there also.
Dalexan

You cannot reference anything from a sub if it's not defined (ord_id, ord_confirm_date).

Why do you want to run a sub on this ? It's simple enough, - you only have the table/query Table_and_Query_Lookup as input ? To me it looks like:

SELECT ord_confirm_date
FROM Table_and_Query_Lookup
WHERE ((ord_id>0) AND  (Active = True));



Regards,
Sven
and then there's that....
Avatar of Dalexan

ASKER

This is the logic of what I am trying to do,

1.)this query will return a table name;

SELECT Table_and_Query_Lookup.TblMediaExport FROM Table_and_Query_Lookup WHERE Active = True

2.)this query has the above query as a subselect within, I need to use that value returned by the subselect in the main select to reference a field within the subselects returned table name.

This is difficult to explain, further explanation may be necessary!
Thanks for your help though.
ASKER CERTIFIED SOLUTION
Avatar of jadedata
jadedata
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK,

This is farfetched, but if you're hooked on SQL then try this (no guarantees;-):

SELECT DLookUp("ord_confirm_date",SubXX.tblXX,"[" & SubXX.TblXX & "].[ord_id])>0") AS ReturnValue
FROM (SELECT Table_and_Query_Lookup.TblMediaExport AS tblXX FROM Table_and_Query_Lookup WHERE Active = True) AS SubXX;

Sven