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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retriving the recordset of parameter query

Status
Not open for further replies.

aaea73

Technical User
Sep 26, 2002
5
US
Hi,

I'm trying to loop through the records resulting from a parameter select query that is used as the record source for an access report. Thus, I tried to retrive the recordset resulting from the parameter select query (named query1). I used:

Dim dbs As Database, rst As DAO.Recordset
Dim qdf As QueryDef
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("query1")
set rst = qdf.openrecordset

I got the error "Too few parameters. Expected 1"

The same error was generated when I used:
Dim dbs As Database, rst As DAO.Recordset
Set dbs = CurrentDb
set rst = qdf.openrecordset("query1")

Any idea about the reason for the error??

Thanks.

 
Have you tried:

Code:
Dim dbs As Database, rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.openrecordset("SELECT * FROM query1;")
 
I've tried your solution. It returned the same error message. Yet, I found the way to make it work. All what I needed is to pass the parameter field name to the query definition. The code would look like this:

Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("query1")
qdf.Parameters(0) = [ParameterFieldname]
Set rst = qdf.OpenRecordset
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top