Parameter Query with ORDER BY (1 Viewer)

S

stevecarter31

Guest
I have a parameter query in Access 2000 as follows:

SELECT test.country, test.name
FROM test
ORDER BY [@Parameter]

I am prompted to input the @Parameter. However, the result is not sorted by the parameter I input (i.e. I input 'Name' or 'Country' without the quote).

Can anyone pls help me on this simple but urgent problem? Thanks a lot!!
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:50
Joined
Feb 19, 2002
Messages
43,257
It is not possible to use parameters to supply the names of objects. You can only use parameters to supply data as in:

Select [yourParm] As AnOutputField,...

or

Where SomeField = [YourParm];

You would need to build the query in code and then run it:

Dim strSQL As String
strSQL = "SELECT test.country, test.name
FROM test
ORDER BY " & [@Parameter] & ";"

DoCmd.OpenQuery strSQL
 

Users who are viewing this thread

Top Bottom