Solved

query result open in Excel - MS Access

Posted on 2013-05-16
7
393 Views
Last Modified: 2013-05-16
Dear Experts,
Can you please give me some idea to open a query result in Excel format from my access form - on a button click?
Thanks in advance
0
Comment
Question by:gtmathewDallas
[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
  • 4
  • 3
7 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39173018
try something like this


private sub Btn_click()

docmd.transferspreadsheet acexport,, "queryName", "C:\folderName\ExcelTest.xls",true


end sub
0
 

Author Comment

by:gtmathewDallas
ID: 39173033
Yes it is helpful but is there any way to open the data in excel other than saving?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39173042
yes, but you need to use recordset of the query.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:gtmathewDallas
ID: 39173054
Ok, can you please show me one example with one or two fields? I have 25 fields there in the query result.
Thanks,
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39173061
dim xlObj as object, Sheet as object
dim rs as dao.recordset, iCol as integer

    Set xlObj = CreateObject("Excel.Application")
    xlObj.Workbooks.Add
    xlObj.Visible = True
    Set rs = CurrentDb.OpenRecordset("QueryName")
    Set Sheet = xlObj.activeworkbook.workSheets("Sheet1")
        For iCol = 0 To rs.Fields.Count - 1
            Sheet.cells(1, iCol + 1).Value = rs.Fields(iCol).Name
        Next
    Sheet.Range("A2").CopyFromRecordset rs  'copy the data
0
 

Author Comment

by:gtmathewDallas
ID: 39173082
but it will not open the excel sheet right?
0
 

Author Comment

by:gtmathewDallas
ID: 39173093
Sorry - Yes It is :) Thanks a lot..
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

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