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

Trouble creating a recordset

Status
Not open for further replies.

BSman

Programmer
Apr 16, 2002
718
US
I'm trying to create a recordset using an existing query and when the code executes I get the error message 3061 "Too few parameters expected 1." Everything sees to be correct, yet I can't get the recordset created. Here's the VBA code I'm using to open the recordset (DAO):

Set rstDelays = dbsCurrent.OpenRecordset("myQuery", dbOpenSnapshot)

I suspect this may be one of those error message that doesn't really tell what the problem is. Can someone help? I've tried a variety of changes, but nothing seems to work. Also, if I put brackets around the query name it can't even find the query.

Thanks,
Bob
 
That error usually occurs when you are expected to input a parameter (i.e. you have a WHERE clause).

 
Here's the full set of code as well as the query:

The query:
SELECT Routes.MasterRoute, Count(TrainDelays.TrainNumber) AS Delays
FROM Routes INNER JOIN TrainDelays ON Routes.RouteCode = TrainDelays.RouteCode
WHERE (((TrainDelays.DelayDate)=[Forms]![fmnuReports]![cboSelectReportDate]))
GROUP BY Routes.MasterRoute
ORDER BY Routes.MasterRoute;

The VBA code:
Dim dbsCurrent As DAO.Database
Dim rstDelays As DAO.Recordset
Set dbsCurrent = CurrentDb

Set rstDelays = dbsCurrent.OpenRecordset "qgrpDailyPerfMatrixSummary", dbOpenSnapshot)


As I mentioned, if I just open the query (for example, in the database window) or even use it in a DLookup statement, there is no problem.

Bob
 
OK, I'm taking the easy way out. I went back to the query and opened the parameter window and entered the forms! statement used as the criteria. Still got the same error message. So I changed the query so it has no criteria and used a select statement with a where clause for the open recordset statement and it works.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top