Solved

DoCmd.TransferSpreadsheet acExport

Posted on 2008-10-17
2
1,820 Views
Last Modified: 2012-05-05
I am running the following script and it works.  The only thing is that it creates a new sheet in the excel workbook rather than over write the existing worksheet.  I need it to overwrite what is out there,,,
 
 
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, QryName, _
            "Z:\Documents\GL\Budget_09\Input_Sheets\Data\IS Budget Exp Sheets_2009.xls", True, QryName & "_payroll_roster"
           
Thank you
0
Comment
Question by:tom0523
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 22744663
I would try Excel automation:

Dim xlApp As Object, xlWb As Object, xlWs As Object
Dim rs As DAO.Recordset
Dim Counter As Long

Set rs = CurrentDb.OpenRecordset(QryName)
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open("Z:\Documents\GL\Budget_09\Input_Sheets\Data\IS Budget Exp Sheets_2009.xls")
Set xlWs = xlWb.Worksheets.Add
With xlWs
    For Counter = 1 to rs.Fields.Count
        .Cells(1, Counter) = rs.Fields(Counter - 1)
    Next
    .Cells(2, 1).CopyFromRecordset rs
End With

xlWb.Save
xlWb.Close
Set xlWs = Nothing
Set xlWb = Nothing
xlApp.Quit
Set xlApp = Nothing
rs.Close
Set rs = Nothing
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

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

910 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

20 Experts available now in Live!

Get 1:1 Help Now