Solved

DoCmd.TransferSpreadsheet acExport

Posted on 2008-10-17
2
1,824 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

680 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