Solved

How to prevent the "Runtime error 2304: Microsoft Office Access can't save output to the specificed file" when export 35,000 records from Stored Procedure in Access 2003 application using Excel 2003?

Posted on 2013-05-09
2
752 Views
Last Modified: 2013-05-16
How to avoid the Runtime error 2304:  Microsof Office Access can't save output data to the specified file in an Access 2003 application using Excel 2003? The application has
35,000 records in a result set from a stored procedure. I am attempting to write the records to an Excel file. The reason I use the Access report rptDtlBranchAll is to create subtotal and total records for the 35,000 detail records.

    With com
       .CommandType = adCmdStoredProc
       .CommandText = "dbo.procDetailBranchAll"
       .Parameters.Append .CreateParameter("@Branch", adVarChar, adParamInput, 4, strBranch)
        Set .ActiveConnection = CurrentProject.Connection
       .Execute
    End With
   
    ExportedFile = CurrentProject.Path & "\Reports\DTLBRANCHALL" & "_" & intYearSP & "_" & Format(Now, "mmddhhnnss") & ".XLS"
       
    DoCmd.OutputTo acOutputReport, "rptDtlBranchAll", 8, ExportedFile
0
Comment
Question by:zimmer9
2 Comments
 
LVL 38

Accepted Solution

by:
Jim P. earned 500 total points
ID: 39158765
Are you sure that path exists?  And the user has write permissions?

Try adding this code ahead of the export:

If Dir(CurrentProject.Path & "\Reports\") <> "." Then
      MKDir CurrentProject.Path & "\Reports"
End IF

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39163538
I think Jim has your answer here...

Can you post the entire code please?

We cannot see where you are loading intYearSP, nor can we see your declarations...

Also, are you quite sure that the format: "8" is valid?
I only ever use the string values, and it woks fine:

acFormatHTML
acFormatRTF
acFormatSNP
acFormatTXT
acFormatXLS
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now