Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 29th, 2006, 07:55 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MarkNorton
Default Using transferSpreadsheet acExport problems

I want to be able to export a query to an Excel Spreadsheet from a form where the user can define the name of the spreadsheet and also to place the spreadsheet in a defined folder. The button is called cmbCreateTable. The report name and the export path are typed into the relevant text boxes on the form frm_AddDataBetweenDates
This is the code I'm using:
Code:
Private Sub cmbCreateTable_Click()

'get the report name from the form

    Dim ReportName As String
    ReportName = [Forms]![frm_AddDataBetweenDates]![txtSpreadsheetName]

'get the path where the spreadsheet will be outputted to


Dim ExportPath As String
    ExportPath = [Forms]![frm_AddDataBetweenDates]![txt_SpreadsheetExportLocation]



    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
            "qry_AllValues_BetweenDates_MN", ExportPath, True , ReportName

            MsgBox "Data Exported to Excel", vbOKOnly
End Sub
Now, this has failed miserably so far. Firstly, with this code, I get the VBA error 3051, it says it " can't open the file C:\Documents and Settings\Mark\Desktop. It is already opened exclusively by another user, or you need permission to view its data". Now, if I type "Test Spreadsheet" into the box marked "txt_SpreadsheetExportLocation" it will output a spreadsheet called "Test Spreadsheet" to my documents folder. I'm pretty sure the problem lies in my usage of the DoCmd.TransferSpreadsheet and I've looked at lots of other examples and can't fathom where I'm going wrong. Any ideas?
 
Old May 30th, 2006, 06:41 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I use the following in similar circumstances to output the results of a query:

DoCmd.OutputTo acOutputQuery, stDocName, acFormatXLS, stPath, True

The True at the end will overwrite an existing spreadsheet of the same name.

HTH

mmcdonal
 
Old May 30th, 2006, 08:20 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MarkNorton
Default

Works perfectly, many thanks for that.






Similar Threads
Thread Thread Starter Forum Replies Last Post
TransferSpreadsheet darkhalf Access VBA 2 February 15th, 2008 04:23 PM
TransferSpreadsheet stealthdevil Access VBA 2 March 16th, 2007 02:45 PM
TransferSpreadsheet kaleb0521 Access VBA 1 August 28th, 2006 12:59 PM
transferspreadsheet ajmil11 Access 3 January 19th, 2006 03:42 AM
TransferSpreadsheet ajmil11 Access VBA 1 January 19th, 2006 02:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.