Yes, your explanation makes sense.
When you move a reference up the list, you are changing its *priority*. So,
if 2 libraries have the same object (e.g. ADO and DAO both have a Recordset
Object), the statement:
Dim rs As Recordset
gives you the higher priority type. If the wrong library has priority, you
get the wrong type (and hence the type mismatch.)
However, if you clearly disambiguate, e.g.:
Dim rs As DAO.Recordset
you get the correct type, regardless of which has priority. Consequently I
strongly recommend that you disambiguate all declarations that *could* be
interpreted as the wrong type, even if you don't use both libraries.
Especially if you are working with a team, where someone else could add
another library later, this is the only way to ensure you code won't fail.
Field and Property (and their plurals) are examples of other objects that
need to be disambiguated.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"sara" <saraqpost@yahoo.comwrote in message
news:22d62eee-52cc-46e2-b621-e6bfdb250b32@q77g2000hsh.googlegroups.com...
On Dec 26, 8:47 pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
Quote:
You don't show the declaration of rs, but presumably you have the line:
Dim rs As Recordset
>
The Type error indicates the object is the wrong type, so probably from
the
wrong library. Try:
Dim rs As DAO.Recordset
>
More info:
http://allenbrowne.com/ser-38.html
>
"sara" <saraqp...@yahoo.comwrote in message
>
news:399faf5c-86ab-435f-85f8-e653cc066dae@i12g2000prf.googlegroups.com...
>
>
>
>
Quote:
I have code (below) that ran as recently as Monday.
We decided to change the location for the output reports, and now the
code errors (13 Type Mismatch) on the query.
>
Quote:
The query runs fine on its own.
The code still runs fine from the .mde.
If I undo the change (single line) I STILL get the error.
The .mdb compiles fine.
Query code at the end of this note.
>
>
Quote:
Set db = CurrentDb
>
Quote:
' This query holds the merchant keys that have RPT = Yes
Set rs = db.OpenRecordset("qrySelMerchForRpt")
'** This is where I get the error
>
Quote:
' Set the path to put the snapped report for each merchant, so it
can be renamed and moved
strPath = "\\server-03\Building19\Sales Audit\HoldMerchRpt\"
>
Quote:
New Code:
Set db = CurrentDb
>
Quote:
' This query holds the merchant keys that have RPT = Yes
>
Quote:
DoCmd.OpenQuery "qrySelMerchForRpt" ' *** I added this to see
if the query would open
'
And it does
>
Quote:
Set rs = db.OpenRecordset("qrySelMerchForRpt") ' Type 13
mismatch
>
Quote:
' Set the path to put the snapped report for each merchant, so it
can be renamed and moved
strPath = "\\server-03\Building19\Sales Reports\Merchants
\HoldMerchRpt\"
>
Quote:
Many thanks! I don't even know where to begin to look on this one.
Will post/provide any info requested.
>
>
Quote:
Query code: (runs fine on its own; Type 13 mismatch on the Set rs =
db.Openrecordset
>
Quote:
SELECT tblMerchant.MerchantKey, Left([MerchFirstName],4) &
Left([MerchLastName],4) AS Merch
FROM tblMerchant
WHERE (((tblMerchant.MerchReport)=-1));- Hide quoted text -
>
- Show quoted text
Allen -
Thank you! That worked, but let me tell you what happened and perhaps
you can explain a bit more to me.
First, I went into my test DB (a copy of production) which errored
yesterday and ran the code to get the error. No error! So, I went
into the production MDB and ran the code, and got the error. I
checked to make sure DAO was in the references and it was (3.6 - I'm
running A2K)
I put your Dim statement in and it ran fine.
But I still wondered why it ran in one and not the other. I checked
"references" to make sure I had the same version of DAO in both - and
found the DAO was near the bottom of my references in the production
MDB (that failed) and near the top in the test version (that worked).
I removed your Dim statement and moved DAO up in the list and it ran!
Why is that? I am set - production runs - but I would like to
understand what is happening so I can learn to not do it again, or fix
it if the error occurs in another db.
Thanks very much -
Sara