Parameter Query with ORDER BY

  • Thread starter Thread starter stevecarter31
  • Start date Start date
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!!
 
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

Back
Top Bottom