All,
I am getting a Run time error 3012: Object "AB_Planinng" already exists. I'm not sure where I messed up in the code. Please help.
HTML Code:
Sub ExportToXlsx()
Dim cdb As DAO.Database, qdf As DAO.QueryDef
Set cdb = CurrentDb
Const xlsxPath = "C:\Users\Desktop\output" & "\AB_Planinng_AA" & ".xlsx"
' create .xlsx file if it doesn't already exist, and add the first worksheet
Set qdf = cdb.CreateQueryDef("AB_Planning", "SELECT [final_report].* FROM final_report")
Set qdf = Nothing
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "AB_Planning", xlsxPath, True
DoCmd.DeleteObject acQuery, "AB_Planning"
Set cdb = Nothing
End Sub
It's been a long time since I have wrote VBA.
Thanks in advance!