Runtime error 3061

  • Thread starter Thread starter Tom Lake
  • Start date Start date
T

Tom Lake

I'm using Access 2002 and have a parameter query called Averages Query
that takes its from date and to date from a form. The criteria line reads

Between [Forms]![ConvertToXML]![FromDate] And
[Forms]![ConvertToXML]![ToDate]

The query works fine if I run it from the query design screen. The
problem is I need to be able to use OpenRecordSet so I can work
with the selected records in a VBA module. When I try to open
the query using

Set rst = dbs.OpenRecordset("Averages Query")

I get

Run-time error '3061':
Too few parameters. Expected 2.

Why is that happening since I'm giving the query both parameters from the
form
and is there a way around it?

TIA

Tom Lake
 
Set rst = dbs.OpenRecordset("Averages Query")

I get

Run-time error '3061':
Too few parameters. Expected 2.

Well, that's right... you have to provide the parameters:

' get a handle to the querydef
With dbs.Querydefs("Averages Query")

' you have to access the Parameters collection -- see help
.Parameters("FromDate") = #2005-01-01#
.Parameters("ToDate") = GetNewDateFromUser()

' now you can get the recordset
Set rst = .OpenRecordset(dbOpenSnapshot, dbForwardOnly)

' now you don't need the querydef any more
End With


Hope that helps


Tim F
 
Set rst = dbs.OpenRecordset("Averages Query")
Well, that's right... you have to provide the parameters:

Thanks! In all my years of programming, I never had to open a parameter
query before.
It just shows you're never too old to learn something new! Now I can start
charging
$4000 per program! 8-)

Thanks again,

Tom Lake
 
Back
Top