My procedure uses Access VBA to run a query to an external database, save the data to Excel, and save to a local folder. I've been using this same procedure with no issues for about year. Now after an O365 update it doesn't compile. I'm self taught and stuck at this point. I tried some updates resulting in a successful compile but in the end the procedure didn't accomplish anything.
Public Sub ExtractToXL()
Dim conn As New ADODB.Connection
Dim rstTD As New ADODB.Recordset
Dim sql As String
Dim xl As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Set xl = CreateObject("Excel.Application")
Set wb = xl.Workbooks.Add()
Set ws = wb.Sheets(1)
conn.CommandTimeout = 0
conn.Open "DSN=Teradata;"
sql = "SELECT * FROM database;"
rstTD.Open sql, conn
For iCols = 0 To rstTD.Fields.Count - 1
ws.Cells(1, iCols + 1).Value = rstTD.Fields(iCols).Name
Next
ws.Range("A2").CopyFromRecordset rstTD
'save and cleanup
ReportPath = Application.CurrentProject.Path & "\Reports\"
wb.SaveAs (ReportPath & "Daily Report " & Format(DateAdd("d", -9, Date), "yyyymmdd") & "-" & Format(DateAdd("d", -3, Date), "yyyymmdd") & ".xlsx")
wb.Close
Set wb = Nothing
Set ws = Nothing
Set xl = Nothing
rstTD.Close
conn.Close
Set rstTD = Nothing
Set conn = Nothing
End Sub
When I run it, I receive: Compile error: Method or data member not found
It highlights ws.Cells