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
Set rst = nothing
etc