troubleshooting Question

Run time error 1004

Avatar of Dale Logan
Dale LoganFlag for United States of America asked on
Microsoft Access
31 Comments1 Solution626 ViewsLast Modified:
I can't figure out what causes this error to show up most of the time, but not all of the time. Here's the code.
Public Function Exporting() As String
    Dim xlObj As Object
    Dim strPath As String
    Dim NewFileName As String
    Dim NewFileWithPath As String
    
    strPath = CurrentProject.Path & "\FinancialExportTemplate.xlsx"
    NewFileName = "\FinancialExport_" & Format(Date, "yyyymmdd") & Format(Now, "hhmmss") & ".xlsx"
    NewFileWithPath = CurrentProject.Path & NewFileName
    
    FileCopy strPath, NewFileWithPath

    'Sends query information to separate worksheets in the 'temp' Excel spreadsheet
    
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportSales", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportCOGS", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportFreight", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportRebates", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportReplants", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportCropLoss", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportRoyltiesPaid", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportSSFIncome", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportExpenses", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportObsoleteInventory", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportInventoryServicing", NewFileWithPath
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportInterest", NewFileWithPath
    
    '===================================================================
    '== Creates the Excel Spreadsheet and performs all the formatting ==
    '===================================================================
  
    Set xlObj = CreateObject("Excel.Application")
    xlObj.Workbooks.Open NewFileWithPath
    xlObj.Application.CalculateFull
    
   ' Tones of formatting.
  
        'Saving & Closing
        
      xlObj.ActiveWorkbook.Save
      xlObj.ActiveWorkbook.Close
        
        'Opens the spreadsheet for viewing
        
       FollowHyperlink NewFileWithPath
        
End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 31 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 31 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros