0

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

June7
  • 19,874
  • 8
  • 24
  • 34
  • 1
    Which code line produces the error? – Andre Feb 22 '21 at 09:35
  • Does this answer your question? [MS Access-CopyFromRecordset](https://stackoverflow.com/questions/44778874/ms-access-copyfromrecordset). Use ADODB recordset. – June7 Feb 22 '21 at 14:47

0 Answers0