Solved

Indirect field reference in SQL statement:  Possible??

Posted on 2002-03-05
5
1,737 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 50 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

749 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