Link to home
Start Free TrialLog in
Avatar of chestera
chestera

asked on

ORDER BY

Hi EE

I have the following and a mental block
Set rsBooked = "SELECT ID FROM tblBooked" & "ORDER BY [ID] ASC"

Not working where have I gone wrong. Any help appreiated

chestera
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
reason being there is no space for your joined string and that created an syntax error

>> Set rsBooked = "SELECT ID FROM tblBooked" & "ORDER BY [ID] ASC"
Why not simply:

    Set rsBooked = "SELECT ID FROM tblBooked ORDER BY [ID] ASC"

or:

    Set rsBooked = "SELECT ID FROM tblBooked ORDER BY 1"

/gustav
everyone is focusing on the SQL, except Rgonzo.

1.  you have to define the SQL correctly, Rgonzo did this  although I cannot understand at all why anybody feels the need to define the SQL string by separating the SELECT and Order By clauses:

strSQL = "SELECT ID FROM tblBooked ORDER BY ID"

2.  The second is that cannot open a recordset by setting a value to a string.

set rsBooked = currentdb.OpenRecordset(strSQL, , dbfailonerror)
Avatar of chestera
chestera

ASKER

Gustav Brock

Getting same error as with my example Compile error Type mismatch. Tried Ryans version same result

Alan
Dale Fye

You are correct just tried Rgonzo 1971 and it worked. Thank you for your comment

Alan
Thank your all for your help