OpenRecordset fails

D

Dion

I have some OpenRecordset / CopyFromRecordset code that I
have used successfully in the past. I created a new copy
of the code, and now get a "Run-time error '13': type
mismatch" error. I have chaecked everything I can think
of, and can not find anything different in this new code
than I had in the original code.

My complete code:
Sub zzz()
Dim xlApp As Excel.Application
Dim db As Database
Dim QDef As QueryDef
Dim rs As Recordset

Set xlApp = CreateObject("Excel.Application")

With xlApp
.Workbooks.Add
.ActiveSheet.Name = "LPlus"
With .Sheets("LPlus")
Set db = CurrentDb
Set QDef = db.QueryDefs("zQTest")
Set rs = QDef.OpenRecordset()
.Range("A2").CopyFromRecordset rs
End With
.ActiveWorkbook.SaveAs "c:\temp\ABSPatList.xls"
.Quit
End With
Set xlApp = Nothing
End Sub


The "Set rs = QDef.OpenRecordset()" is where I get the
error. The query "zQTest" is a simple SELECT query. I
verified this works.

What am I missing?

Thanks
Dion
 
T

Ted Allen

Did you check the references to see if they are
different. If the original code was using DAO and you
are now using it in a different DB it may have ADO
referenced by default.
 
D

Dan Artuso

Hi,
Yes, but if ADO is included in the references, you have to 'dis-ambiguate'
your
recordset object (since both DAO and ADO have recordset objects)

Dim rs As DAO.Recordset
or get rid of the ADO reference

HTH
Dan Artuso, MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top