We help IT Professionals succeed at work.
Get Started

From access to excel : COPYFROMRECORDSET DAO - compile error invalid use of property

mytfein
mytfein asked
on
627 Views
Last Modified: 2012-05-06
Dear Experts,
can u pls explain why i'm getting a compile error at the statement that:

sets:  rst = nothing

this logic is to open existing formatted spreadsheet and populate with selected columns.

'============ in a public module
Public objExcel                           As Excel.Application
Public objExcelActiveWkbs                 As Excel.Workbooks
Public objExcelActiveWkb                  As Excel.Workbook
Public objExcelActiveWs                   As Excel.Worksheet

'==========
Public Sub e005_CopyFromRecordSet(strSql As String, _
                                  strExcelPath As String)

Set objExcel = CreateObject("Excel.Application")
 
Set objExcelActiveWkbs = objExcel.Workbooks
objExcelActiveWkbs.Open FileName:=strExcelPath
Set objExcelActiveWs = objExcel.ActiveSheet

objExcel.Visible = True

Dim db                    As DAO.Database
Dim rst                   As DAO.Recordset
Dim fld                   As DAO.Field


Set db = CurrentDb
Set rst = db.OpenRecordset(strSql)

objExcelActiveWs.Range("A4").CopyFromRecordset rst


With objExcelActiveWs
     With .Cells
          .Select
          .EntireColumn.AutoFit
     End With
End With


objExcel.ActiveWorkbook.Save
'objExcelActiveWkb.Save


Set objExcel = Nothing
Set objExcelActiveWkb = Nothing
Set objExcelActiveWkbs = Nothing
Set objExcelActiveWs = Nothing

rst.Close
db.Close

===========> get compile error here - invalid use of property
rst = Nothing
db = Nothing
fld = Nothing

End Sub
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE