Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem w/ Overwriting Excel Export from Access 2007

Posted on 2014-03-27
6
Medium Priority
?
1,242 Views
Last Modified: 2014-04-15
I am running some code that exports data based on a query to an Excel file (.xlsx) executed by a button. Previously I was exporting to a .xls file but since I have changed it to an Excel 2007 format I noticed that the file is not being overwritten. The crazy this is that when I navigate to the directory where the file is going the modified date/time is updated and the size of the file increases but when I open it I see the exact same data in there that I exported on the first execution of the code. Below is the code that I am running.

Dont know if this matters but I am exporting the file to a Sharepoint site although I stating the fully resolved path. Any assistance with this would be much appreciated.

Thank you

Public Function ExportFormData()

    On Error GoTo ErrorHandler
    
    DoCmd.SetWarnings False
    
    Dim strDashboardPath As String
    Dim strQryVacRecords As String
    
    strDashboardPath = "\\teamspace\sites\RD_TEAM\ExcelExports\"
    strQryVacRecords = strDashboardPath & "VAC_RECORDS_2014.xlsx"
    
    DoCmd.TransferSpreadsheet TransferType:=acExport, SpreadsheetType:=acSpreadsheetTypeExcel12Xml, TableName:="QRY_VAC_RECORDS", Filename:=strQryVacRecords, HasFieldNames:=True
    
    DoCmd.SetWarnings True
    
ErrorHandlerExit:
    Exit Function
    
ErrorHandler:
    MsgBox "Error No: " & Err.Number _
        & ";Description: " & Err.Description
    Resume ErrorHandlerExit

End Function

Open in new window

0
Comment
Question by:spaced45
5 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 39960198
Is it perchance appending the data instead of replacing it?
0
 
LVL 1

Author Comment

by:spaced45
ID: 39961600
I dont think so because I went back into the file before and after an export knowing that records were added and the row count was the same.
0
 
LVL 19

Expert Comment

by:regmigrant
ID: 39985418
since excel 2007 deprecated the sync between excel and sharepoint it might have changed the handling of those file types

 DoCmd.TransferSpreadsheet expects to create a new workbook (I think) so one alternative might be to check for an existing one and delete before transfer

If the problem goes away when you specifiy a non-sharepoint location then it could be you need to explicitly publish/checkin the updates in SharePoint, in Excel that would be:
Workbooks(ActiveWorkbook.Name).CheckIn
0
 
LVL 10

Assisted Solution

by:broro183
broro183 earned 750 total points
ID: 39985579
I've read that DoCmd.TransferSpreadsheet requires the path length to be less than 64 characters (see the first link). The example string that you have provided is only 60 characters so, if your real file uses the same string, this shouldn't be the cause of your problem. Is the example string the same as the one in your real file?

I think Regmigrant may be onto something with his suggestion of checking if the file needs to be "checked in".

Rob
0
 
LVL 46

Accepted Solution

by:
aikimark earned 750 total points
ID: 39985781
I've seen problems where the transferspreadsheet method is stuck in the past when using the more recent versions (2007 and after).  The method doesn't realize that the old 64k row limit has been increased with the new versions.

I usually advise developers and users to replace the transferspreadsheet method with an instantiation of an Excel object and use the CopyFromRecordset range method.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

877 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