Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Parameter Query to Pass into FROM statement

Status
Not open for further replies.

eerich

IS-IT--Management
Nov 2, 2003
124
0
0
US
Hello everyone

I need help with a parameter query where I need to pass the table name into the FROM statement at run time. I have a number o ERP modules each in a different table so I just to get he table name inserted when I run it. The query I've tried gives an error. see my code below:

Code:
PARAMETERS [SRC] TEXT (50);
SELECT OBJID
FROM (SELECT OBJID FROM ERPTBL) AS ERPSRC
WHERE ERPTBL = [SRC];

The error message I receive is that ERPTBL is not recognized. Any help with this is appreciate4d.
 
You can't parameterize the table name. You could use a little DAO code to modify the SQL property of a query as per faq701-7433.

Another solution would be to create a union query based on all of your different tables with a calculated column that identifies the source table.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Duane

Can you provide an example for the second solution? Mu tables are"
AR
AP
GL
FA
PO

My field in each table is ObjID

How would I construct the syntax for your 2nd solution?
 
[tt]
Select 'AR' As MyTable, ObjID From AR
Union
Select 'AP', ObjID From AP
Union
Select 'GL', ObjID From GL
Union
Select 'FA', ObjID From FA
Union
Select 'PO', ObjID From PO
[/tt]
You may - if you want - include other fields from your tables.

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
The only small modification of Andy's SQL would be to use "Union All" rather than just "Union". I think it might perform a little better.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Yes, "Union All [...] might perform a little better. " (since the db engine does not have to eliminate duplicates), but the outcome (data) should be the same. :) (since there will NOT be any duplicates)

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Andy,
Correct but there might have been duplicate ObjID values within a table.

The final SQL might look like:

Code:
SELECT ObjID 
FROM quniModules
WHERE MyTable = "AR";

Or you could use some type of parameter (hopefully a control on a form) for the MyTable value.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
UNION ALL Worked perfectly. Many thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top