I am getting the above error message while running the below function from Access VBA.
Function WrongEntries()
Dim dbs As Database
Dim sht As Worksheet
Set dbs = CurrentDb
Set rfQuery = dbs.OpenRecordset("5G Negative Cycle Times")
Set rgQuery = dbs.OpenRecordset("5G High Cycle Times")
Set excelapp = CreateObject("Excel.application", "")
excelapp.Visible = True
Set targetworkbook = excelapp.Workbooks.Open("C:\GDC Reporting\Template\5G Wrong Entries_Blank.xlsx")
targetworkbook.Worksheets("Negative Cycle Times").Range("A2").CopyFromRecordset rfQuery
Set targetworkbook = excelapp.Workbooks.Open("C:\GDC Reporting\Template\5G Wrong Entries_Blank.xlsx")
targetworkbook.Worksheets("Cycle Times >5 weeks").Range("A2").CopyFromRecordset rgQuery
targetworkbook.RefreshAll
targetworkbook.Application.DisplayAlerts = False
targetworkbook.Application.ScreenUpdating = False
end function
I have checked the references and all the libraries are included to run this code however I am still getting the above error. I am using MS Office 2016 application on office 365 platform. Using this code I am just trying to copy dataset from predesigned query to excel sheet.
Please help me to resolve this error. Please let me know in case any further info is needed.
Thank you so much in advance.
Thanks,
Shobhit