-
I am trying to implement a sort function for displaying query results in a MSHFlexgrid from an access database. The user selects which field they would like to sort by from a list box. I am getting a syntax error on the following line:
SelPM = "SELECT * FROM Pattern ORDERED BY " + Selected + ";"
I have also tried:
SelPM = "SELECT * FROM Pattern ORDERED BY """ + Selected + """;"
and a few other combinations.
The variable 'Selected' is specified by the user by filling in the sort dialog box. The proper value is being put into the 'Selected' variable, I can see it in the debugger. Any ideas would be appreciated. Thank you.
-
The syntax is ORDER BY not ORDERED BY, also instead of using the + to concatenate strings use the & symbol and I would also suggest putting Single quotes (') around the string unless you expect the value to inclued single quotes.
Code:
SelPM = "SELECT * FROM Pattern ORDER BY '" & Selected & "';"
or if you expect the variable Selected to include single quotes then use this instead, Chr(34) returns a double quote......
Code:
SelPM = "SELECT * FROM Pattern ORDERED BY " & Chr(34) & Selected & Chr(34) & ";"
-
Thank you. It works now. I had to leave out the single quotes though.?.
-
Yeah, sorry about that, you only need the quotes around WHERE statements and the like, it was about 3 AM when I wrote that, sorry. ;)
-
No problem, I appreciate the help. I'm only about 6 weeks into programming but I'm having fun.