refer to a field using a variable

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I have a field which has several different field names in
it (fnames)in a table called table1.
What I want to be able to do is return the value of the
field which is specified in my Fnames field using a query.

fnames field1 field2 field3 field4
field4 1 15 10 39
field1 12 18 30 7

I would like to return a value of 39 for the first row and
12 for the second.

i have tried
("table1")('[fnames]')
and several different combinations- but can't get the
syntax right.

any help would be greatfully appreciated.
thanks
 
Hi,


A field name is not data readily usable by a database engine, as data.

You can try:


SELECT SWITCH( fnames="field1", field1, fnames="field2", field2,
fnames="field3", field3, fnames="field4", field4, True, Null) FROM MyTable




Hoping it may help,
Vanderghast, Access MVP
 
thanks Michel

I'll try it.
-----Original Message-----
Hi,


A field name is not data readily usable by a database engine, as data.

You can try:


SELECT SWITCH( fnames="field1", field1, fnames="field2", field2,
fnames="field3", field3, fnames="field4", field4, True, Null) FROM MyTable




Hoping it may help,
Vanderghast, Access MVP


I have a field which has several different field names in
it (fnames)in a table called table1.
What I want to be able to do is return the value of the
field which is specified in my Fnames field using a query.

fnames field1 field2 field3 field4
field4 1 15 10 39
field1 12 18 30 7

I would like to return a value of 39 for the first row and
12 for the second.

i have tried
("table1")('[fnames]')
and several different combinations- but can't get the
syntax right.

any help would be greatfully appreciated.
thanks


.
 
Back
Top