Re: OpenRecordSet problem

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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 on
this
line.

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
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

--
Marsh
MVP [MS Access]



.



Relevant Pages

  • Re: Member or Data Member not Found
    ... you've removed the reference to ADO. ... your declaration for tdf is incorrect. ... 2002 only references ADO, but you can add a reference to DAO. ... You must disambiguate as Dim rst As DAO.Recordset. ...
    (microsoft.public.access.formscoding)
  • Re: Make backup copy when closing
    ... I'll see about the DAO vs. ADO later. ... With any code module open, select Tools | References from the menu bar, ... extra vbNullChar at the end, ...
    (microsoft.public.access.modulesdaovba)
  • Re: button that prompts for a value and then enters it into a field
    ... Dim rs As Object ... Access uses either DAO or ADO to communicate with the underlying Jet ... The FindFirst method is only available in DAO recordsets, ...
    (microsoft.public.access.forms)
  • Re: Possible DAO and ADO conflicts
    ... >> I have a legacy application which only has DAO references. ... >> I'm assuming that ADO would be able to create newer versions of Access ... > You can fool around with the order of the libraries in the reference list to ...
    (microsoft.public.vb.database)
  • Re: Warum funktioniert Me.RecordsetClone nicht? (VBA)
    ... Dim rsd as Dao.Recordset ... pro DAO: erheblich schneller als ADO auf Jet-Datenbanken, ... Recordsets mit dem SHAPE-Provider ...
    (microsoft.public.de.access)