Solved

Sub Select in MS Access 2002 not working

Posted on 2003-12-02
7
667 Views
Last Modified: 2008-02-01
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;
0
Comment
Question by:Dalexan
7 Comments
 
LVL 5

Expert Comment

by:morpheus30
ID: 9861006
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;
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9861028
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.
0
 
LVL 9

Expert Comment

by:svenkarlsen
ID: 9861097
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
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 32

Expert Comment

by:jadedata
ID: 9861155
and then there's that....
0
 

Author Comment

by:Dalexan
ID: 9861260
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.
0
 
LVL 32

Accepted Solution

by:
jadedata earned 50 total points
ID: 9861486
You are going to need to write the sql for the main query out in VBA before running it.  You can not force a field value directly into a query syntax in this manner.


  dim ssql as string
  dim stablename as string
  stablename = dlookup("tblMediaExport","Table_and_Query_Lookup","([Active] = true)")
  ssql = "SELECT ord_confirm_date "
  ssql = ssql & "FROM [" & stablename & "] "
  ssql = ssql & "WHERE (ord_id>0);


then assign the ssql variable VALUE to a recordsouce or rowsource property somewhere.

0
 
LVL 9

Expert Comment

by:svenkarlsen
ID: 9862007
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
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now