ORDER BY using value from a text box within a form

S

samymelbourne

Hi,
I have the following query which will not work. TextBox has a string: "ID"
SELECT * FROM TableName ORDER BY Forms![TableForm]![TextBox]
However when I use the same query like this I get the desired results:
SELECT * FROM TableName ORDER BY ID.

I would like to be able to modify the query accordingly based on string
value of TextBox. I am at a witts end. All help is greatly appreciated in
advance.
Thanks
 
B

BruceM

You can order by a field, including a calculated field, but the text box is
not part of the query, so you can't order by its contents. In any case it
is a single value. It would be like telling you to sort a list of names by
"D".

What exactly do you hope to do?
 
K

KARL DEWEY

You can order by a field, including a calculated field,
If you do not have many choices then you can use a calculated field like
this --
SortField: IIF([Forms]![TableForm]![TextBox] ="ID", [ID],
IIF([Forms]![TableForm]![TextBox] ="Sale", [Sale],
IIF([Forms]![TableForm]![TextBox] ="Buy", [Buy], [SomeOtherField)))

--
KARL DEWEY
Build a little - Test a little


BruceM said:
You can order by a field, including a calculated field, but the text box is
not part of the query, so you can't order by its contents. In any case it
is a single value. It would be like telling you to sort a list of names by
"D".

What exactly do you hope to do?

samymelbourne said:
Hi,
I have the following query which will not work. TextBox has a string: "ID"
SELECT * FROM TableName ORDER BY Forms![TableForm]![TextBox]
However when I use the same query like this I get the desired results:
SELECT * FROM TableName ORDER BY ID.

I would like to be able to modify the query accordingly based on string
value of TextBox. I am at a witts end. All help is greatly appreciated in
advance.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top