Link to home
Start Free TrialLog in
Avatar of spaced45
spaced45Flag for United States of America

asked on

Problem w/ Overwriting Excel Export from Access 2007

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

Avatar of nutsch
nutsch
Flag of United States of America image

Is it perchance appending the data instead of replacing it?
Avatar of spaced45

ASKER

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.
Avatar of regmigrant
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
SOLUTION
Avatar of Rob Brockett
Rob Brockett
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial