Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Indirect field reference in SQL statement:  Possible??

Posted on 2002-03-05
5
Medium Priority
?
1,853 Views
Last Modified: 2008-02-26
WITHOUT using VBA and only using Access 2000, can I create a two-table query where the contents of a one field in one table can become the column name or field name in another.

TableOne has the following fields:
Field1 Text   10
Field2 Text   10
Field3 Text   10

TableTwo has one record and one field:
FieldName Text  10    <-  Holds the value "Field2"

I want to select only Field2 from table one.  I've tried the Eval() function without success:

select eval([TableTwo]![FieldName]) from TableOne

Thanks - gene
0
Comment
Question by:genehead
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 54

Expert Comment

by:nico5038
ID: 6842806
Don't think so, but perhaps another expert knows how to fool the access SQL interpreter...

Remains my Q: Why ?

Nic;o)
0
 
LVL 1

Expert Comment

by:S2
ID: 6842852
do you mean like this?
SELECT (SELECT tbl2.fld1 FROM tbl2) FROM tbl1;

this would give you the value of tbl2.fld1 the number of records you have in tbl1.

if you need the values of tbl1 that are in the field that has the name in tbl2.fld1 then you will have to compose it in VBA, there is no escaping it.
0
 
LVL 1

Expert Comment

by:matthewroberts
ID: 6843265
Why don't you want to code in VBA and build the sql string on the fly??
0
 
LVL 3

Accepted Solution

by:
pbryan earned 200 total points
ID: 6843559
you could do it with a couple of queries, but like nico says "why?"

--------------------

Query 1:

Union all the fields together
Select "Field1" as FieldName, Field1 as FieldValue from TableOne UNION Select "Field2" as FieldName, Field2 as FieldValue from TableOne UNION Select "Field3" as FieldName, Field3 as FieldValue from TableOne

Query2:
Join union query to TableTwo on fieldname column (this filters the columns)

Query3:
Create crosstab based on Query 2, use FieldName as column header
0
 
LVL 1

Author Comment

by:genehead
ID: 6847945
Accepting pbryan's comment as answer.  This is then kind of solution I was looking for.  I thought of UNION but didn't take it to the crosstab stage.  Good thinking pbryan.  Thanks - Gene
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

618 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