Kemidan2014
Board Regular
- Joined
- Apr 4, 2022
- Messages
- 229
- Office Version
- 365
- Platform
- Windows
So i have a small bit of code that I am using on a Command Button to export a query to Excel. it has been working until today where all i did to the code was move the Saveas and Close command.
according to google the error says its either related to too many fields (query has only 15 fields?) or exported file already exists but before today i was able to overwrite the existing file data. I checked and confirmed the file was not open when i clicked the button
Here is my code
I changed where the save and close were because when i did use it it was almost like it was opening twice so i was trying to resolve the extra open excel instance.
according to google the error says its either related to too many fields (query has only 15 fields?) or exported file already exists but before today i was able to overwrite the existing file data. I checked and confirmed the file was not open when i clicked the button
Here is my code
VBA Code:
Private Sub Qualitymetrics_Click()
'Declare stuff
Dim excelapp As Object
Dim wb As Object
Dim openpath As String
openpath = "O:\1_All Customers\Current Complaints\ComplaintMetricsQuery.xlsx" 'Set file path
Set excelapp = CreateObject("Excel.Application")
Set wb = excelapp.Workbooks.Open(openpath)
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "ComplaintMetricsQuery", "O:\1_All Customers\Current Complaints\ComplaintMetricsQuery.xlsx", True
wb.SaveAs (openpath) '<---Originally after End if and before wb.close was only wb.save not save as.
wb.Close '<---Originally after End if AND disabled
If MsgBox("Metric's data is updated, Would you like to review the report?", vbYesNo) = vbYes Then
excelapp.Workbooks.Open (openpath)
excelapp.Visible = True
End If
End Sub
I changed where the save and close were because when i did use it it was almost like it was opening twice so i was trying to resolve the extra open excel instance.