Hi, Brendan:
[] works fine for the query in the SQL Statement. In my application, the
query name is actually an arugment passing through a general procedure.
For example:
Public sub MyProcedure (QueryName as String)
.....
Set rs1 = dbs.OpenRecordset _
("SELECT * FROM " & [QueryName] & " ORDER BY Field1")
.....
or I tried:
.......
Dim aa as string
aa = QueryName
Set rs1 = dbs.OpenRecordset _
("SELECT * FROM " & [aa] & " ORDER BY Field1")
Non of them seems working. What syntex should they be?
Many thanks.
--
Jim in Northwest
Brendan Reynolds said:
The example below works for me, using the 'Quarterly Orders by Product'
cross-tab query from Northwind. As I said, if you still can't get it to
work, try posting the SQL for the 'MyQuery' query. Does that query work
on
it's own?
Public Sub TestSubX()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT * FROM [Quarterly Orders by Product] ORDER BY
CustomerID"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
Debug.Print rst.Fields("CustomerID")
rst.Close
End Sub
--
Brendan Reynolds (MVP)
message Thanks for your suggestions!
I am using the following statement:
Set rs1 = dbs.OpenRecordset _
("SELECT MyQuery.* FROM MyQuery ORDER BY MyQuery.Field1")
The error message I got is
Runtime error 3131 - Syntex error in FORM Clause
If I replace the query with a tablename, everthing works fine. I am
using
Access 2002 and MyQuery may be a cross-tab query.
Any more suggestions?
Thanks!
--
Jim in Northwest
:
Provided that the query 'MyQueryName' includes the field 'field1' in
its
SELECT clause, it should work, yes.
If you still can't get it to work, try posting the SQL for the
'MyQueryName'
query.
--
Brendan Reynolds (MVP)
message We can do the following to open a query as recordset:
Set rs = dbs.OpenRecordset("MyQueryName")
Can we do the following to sort a field inside the query?
Set rs = dbs.OpenRecordset("select * from MyQueryName order by
field1")
I didn't have mush luck for the last sort SQL statement to open the
recordset. Any suggestion?
Thanks