|
-
Feb 19th, 2001, 04:35 PM
#1
Thread Starter
New Member
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.
-
Feb 19th, 2001, 04:56 PM
#2
Fanatic Member
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) & ";"
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Feb 20th, 2001, 12:14 PM
#3
Thread Starter
New Member
Thank you. It works now. I had to leave out the single quotes though.?.
-
Feb 20th, 2001, 12:30 PM
#4
Fanatic Member
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.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Feb 20th, 2001, 12:38 PM
#5
Thread Starter
New Member
No problem, I appreciate the help. I'm only about 6 weeks into programming but I'm having fun.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|