Solved

Problem w/ Overwriting Excel Export from Access 2007

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 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

16 Experts available now in Live!

Get 1:1 Help Now