Re: OpenRecordSet problem
- From: "Douglas J Steele" <NOSPAM_djsteele@xxxxxxxxxxxxxxxxx>
- Date: Thu, 4 May 2006 16:05:13 -0400
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.
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Paul Hammond" <phammond@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0A4D55FD-5E57-4AB1-B4A7-69CA5A96399F@xxxxxxxxxxxxxxxx
I tried your script and am getting a runtime error 13 Type Mismatch onthis
line.something
For Each parm In qdf.Parameters
BTW, is there a simpler approach that would avoid all this?
TIA
Paul
--
Can't we all just get along?
"Marshall Barton" wrote:
Paul Hammond wrote:
Can someone tell me why this is not working. I swear I used to do
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
--
Marsh
MVP [MS Access]
.
- References:
- Re: OpenRecordSet problem
- From: Marshall Barton
- Re: OpenRecordSet problem
- Prev by Date: Re: OpenRecordSet problem
- Next by Date: Re: How do I add a calculated field to a report?
- Previous by thread: Re: OpenRecordSet problem
- Next by thread: Re: How do I add a calculated field to a report?
- Index(es):
Relevant Pages
|