Can't open recordset based on query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

rs.open "queryname", currentproject.connection

gives me an error

it says "expecting sql statement"

I'm using adodb recordset.

My access book says this should work, any clues you can throw my way ???
 
It does work. In order to determine why it's not working for you, we'll
probably need to know more of the context. Here's an example that works for
me. How does your code differ from this code?

Public Sub TestSub2()

Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset

'Query1 is the name of a saved select query.
rst.Open "Query1", CurrentProject.Connection
Debug.Print rst.Fields(0).Value
rst.Close

End Sub
 
According to Access Help , the "Source" argument can be a Command object,
Table name, an SQL String, a SP ... but an Access Query is not mentioned.

I normally use an SQL String as the Source.

Check Access VB Help on the Open Method of the ADO Recordset object.
 
Thanks, Brendan

It worked in a quick test I just done in A2002.

I wondered why Access Help didn't mentioned Access Query as a possible
Source. I still use DAO mainly but it good to know that an Access Query can
also be used.
 
Well, that help topic is part of ADO help rather than Access help, the
author (or authors) may not necessarily have been very familiar with Access,
and may not have perceived a need to distinguish between a stored procedure
and a query.

The help topic doesn't mention views, either, and the name of a view is
certainly a legitimate value for the Source property of an ADO recordset.

--
Brendan Reynolds (MVP)

Van T. Dinh said:
Thanks, Brendan

It worked in a quick test I just done in A2002.

I wondered why Access Help didn't mentioned Access Query as a possible
Source. I still use DAO mainly but it good to know that an Access Query
can
also be used.

--
Cheers
Van T. Dinh
MVP (Access)
 
Back
Top