Solved

Problem w/ Overwriting Excel Export from Access 2007

Posted on 2014-03-27
6
1,111 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
6 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 250 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 45

Accepted Solution

by:
aikimark earned 250 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

760 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

21 Experts available now in Live!

Get 1:1 Help Now