OpenRecordSet problem

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

Guest

Can someone tell me why this is not working. I swear I used to do something
just like this.

Set rstTemp = CurrentDb.OpenRecordset("qrySolictorReports")
MsgBox "There are " & rstTemp.RecordCount & " records."

I keep getting runtime error 3061
Too few parameters. Expecting 2

Any suggestions?

TIA

Paul Hammond
Richmond, VA
 
Paul said:
Can someone tell me why this is not working. I swear I used to do something
just like this.

Set rstTemp = CurrentDb.OpenRecordset("qrySolictorReports")
MsgBox "There are " & rstTemp.RecordCount & " records."

I keep getting runtime error 3061
Too few parameters. Expecting 2


Apparently, the query has some parameters.

When you open a recordset using DAO directly (instead of
Access taking care of it in a report's record source), then
you need to add code to resolve the parameter values.
Without knowing anything about your query, I'll take a guess
that this might work:

Dim db As Database
Dim qdf As QueryDef
Dim parm As Parameter
Set db = CurrentDb()
Set qdf - db.QueryDefs!qrySolictorReports
For Each parm In qdf.Parameters
parm.Value = Eval(parm.Name)
Next parm
Set rstTemp = qdf.OpenRecordset
rstTemp.MoveLast 'populate entire recordset
MsgBox "There are " & rstTemp.RecordCount & " records."
rstTemp.Close : Set rstTemp = Nothing
Set qdf = Nothing
Set db = Nothing
 
I tried your script and am getting a runtime error 13 Type Mismatch on this
line.

For Each parm In qdf.Parameters

BTW, is there a simpler approach that would avoid all this?

TIA

Paul
 
I'm assuming you've got references set to both ADO and DAO (by default,
Access 2000 and 2002 only have a reference set to ADO. Access 2003 jhas
references to both by default, with the ADO reference being higher in the
list).

There are objects with the same name in the two models. Your code is
attempting to use DAO methods. If you don't disambiguate the declarations,
you'll end up with the ADO version of the object, since ADO is higher in the
references.

It's possible that your original code was correct (that there aren't
parameters involved). To check, ensure your declaration is

Dim rstTemp As DAO.Recordset

If that doesn't work, then change what Marsh gave you to:

Dim parm As DAO.Parameter

To be totally correct, you could also change the first two declarations to

Dim db As DAO.Database
Dim qdf As DAO.QueryDef

but that's not as critical, as the Database and QueryDef objects only exist
in the DAO model, so there's no ambiguity in the declaration.
 
Back
Top