Solved

Exporting from Access to Excel (Docmd.Transferspreadsheet) in a live window

Posted on 2004-03-24
9
573 Views
Last Modified: 2008-03-03
I have employed the code for the docmd.transferspreadsheet (thanks Nico).

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryMASTER_Temp", "C:\ListExport.xls"

However, instead of exporting and saving to the C:\ListExport.xls, I would like to export to a live window (I know how to open a live window in excel)

    Dim oApp As Object

    Set oApp = CreateObject("Excel.Application")
    oApp.Visible = True
    'Only XL 97 supports UserControl Property
    On Error Resume Next
    oApp.UserControl = True

Any suggestions on how to export in the window?

Thanks!
0
Comment
Question by:cassyerin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 32

Expert Comment

by:jadedata
ID: 10669071
Greetings cassyerin!

  That command is in the category of a menu command and will not function in ways that say "CopyFromRecordset" would.

  With CopyFromRecordset you would set up the records in a dbdynaset type queue and pass them to an excel worksheet via CopyFromRecordset


regards
jack
0
 
LVL 32

Expert Comment

by:jadedata
ID: 10669157
I use copyfromrecordset for all spreadsheet creations for end users because it shows the work as it occurs...
0
 

Author Comment

by:cassyerin
ID: 10671355
Do you know where I'm going wrong?

---


Dim objXLWb As Object
Dim objXLSheet As Object
Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset(strSQL)

'Start Excel
Set objXLApp = CreateObject("Excel.Application")
objXLApp.Visible = True

'Open Worksheet & Activate
Set objXLWb = objXLApp.Workbooks.Add
Set objXLSheet = objXLWb.ActiveSheet

'CopyRecordset
objXLSheet.CopyFromRecordset rs
objXLSheet.Columns.AutoFit
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 3

Accepted Solution

by:
Jeremyw earned 125 total points
ID: 10671818
casseyerin,

this is how I am doing it.  change the filename in your DoCmd line to reference strFileName

Dim strFileName As String

strFileName = "C:\ListExport.xls"

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryMASTER_Temp", strFileName

Dim xlApp As Excel.Application
Set xlApp = New Excel.Application
xlApp.Visible = True
xlApp.Workbooks.Open strFileName

'Excel Formatting
    xlApp.Rows("1:1").Select
    xlApp.Selection.Insert Shift:=xlDown
    xlApp.Selection.Font.Bold = True
    With xlApp.Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With


Jeremy
0
 

Author Comment

by:cassyerin
ID: 10671836
I can get it to run using the docmd. option, however, I want it to export into excel so that data manipulation can be made and the user can choose where to save it.

0
 
LVL 32

Assisted Solution

by:jadedata
jadedata earned 125 total points
ID: 10671939
These changes do  not mean you did this wrong, just different


Dim objXLWb As Object
Dim objXLSheet As Object
Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset(strSQL)
'where is the strsql value
'did you actually write this to do a spreadsheet on ANY recordset???

'Start Excel
Set objXLApp = New Excel.Application
objXLApp.Visible = True

'Open Worksheet & Activate
Set objXLWb = objXLApp.Workbooks.Add
Set objXLSheet = objXLWb.worksheets(1)
'delete other 2 worksheets  
objXLWb.worksheets(3).delete
objXLWb.worksheets(2).delete

Add fields column headers
for x = 0 to rs.fields.count-1
  objxlws.cells(HeaderRowNum, x+1) = rs.fields(x).name
next x

'CopyRecordset
objXLSheet.range("A4").CopyFromRecordset rs
objXLSheet.Range("A:Z").entirecolumn.AutoFit
0
 
LVL 2

Expert Comment

by:rsclark
ID: 10676033
0
 
LVL 39

Expert Comment

by:stevbe
ID: 12481235
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Split: jadedata {http:#10671939}, Jeremyw {http:#10671818}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

stevbe
EE Cleanup Volunteer
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

726 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