Variable Field Name

R

rdolds

I am attempting to use SQL to make a query choose a field based on a user
input into a table. A simple example would be a user inputs a number (74).
A query is ran to lookup data in a table with fields 1 through 100. I have
unsuccessfully tried to use a FROM statement similar to:

DataTable.[UserInputTable.Number]

Can I make a field name a variable?
 
R

rdolds

I do use a form as input. The user inputs a request for a report to be
generated by entering the parameters for a specific chemical distribution
unit test. The information is saved in a table and the subsequent
information used for the queries.
--
Robert Olds


KARL DEWEY said:
You should use a form as input or a prompt in a query.

rdolds said:
I am attempting to use SQL to make a query choose a field based on a user
input into a table. A simple example would be a user inputs a number (74).
A query is ran to lookup data in a table with fields 1 through 100. I have
unsuccessfully tried to use a FROM statement similar to:

DataTable.[UserInputTable.Number]

Can I make a field name a variable?
 
J

John Vinson

I do use a form as input. The user inputs a request for a report to be
generated by entering the parameters for a specific chemical distribution
unit test. The information is saved in a table and the subsequent
information used for the queries.

It's not necessary to take the extra step of saving the form value
into a table, and in fact that simply makes things harder. You can use
a query criterion

=[Forms]![YourFormName]![YourControlName]

to get the criterion directly from the Form.

If you do store the criteria in a table, you can't then use them
(directly anyway) as query criteria; however, you can create a query
Joining your data table to the criterea table.

John W. Vinson[MVP]
 
Top