Solved

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

Posted on 2004-03-24
9
569 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
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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

16 Experts available now in Live!

Get 1:1 Help Now