Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I open an ADO recordset from a stored query

Status
Not open for further replies.

hopper

Programmer
Dec 5, 2000
27
0
0
US
I'm sure this is simple, but I'm having a heck of a time trying to open an ADO recordset based off of a stored query.
I am using access 2002
Code looks something like this.

dim conn as adodb.connection
dim rs as adodb.recordset
set conn = currentproject.connection
set rs = new adodb.recordset

'normally I would do something like this
'rs.open "SELECT * FROM tblTest", conn
'however I want to use a query saved in my database

rs.open qryMyQuery, conn
'this doesn't seem to work as I'm sure the open method is looking for a string.

Any help is greatly appreciated.

Thanks,

Scott
 
Hi Hopper

If the query is already saved in your database why are you using ADO at all ??

use a local recordset such as



Dim MyRs as recordset

Set MyRs = Currentdb.openrecordset("Select * FROM .. WHERE... ETC...")

 
The reason I'm trying to use the saved query name is because it is a very large SQL statement and I am trying to keep my code as clean as possible. Any overhead associated with ADO would not be an issue as this is a smaller system with few users.
 
hopper,
do

dim qd as querydef,db as database
set db = currentdb
set qd = db.querydefs("somequery")
openrecordset(qd.sql)
-jsteph
 
I will give that a shot in just a few minutes jsteph.

Thanks for your help.
 
That works great jsteph, THANKS!!!

now....

is there a way to pass in a parameter value to the query in that same code?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top