Results 1 to 5 of 5
  1. #1
    gokul1242 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    5

    Export Filtered ListBox output to a Excel Sheet

    Hi Currently i have a form Which has three combo box .then i have a search button which runs a query based on the values selected in the three combo boxes and shows the results in a list box below.see the image for the form here.Click image for larger version. 

Name:	form.jpg 
Views:	15 
Size:	71.0 KB 
ID:	9430

    Now i want to add a button called "Export to excel" which will export the list box results to a Ms-excel sheet.how to go about doing this in vba. i have gone through threads related to this same issue but unfortunately none of them works ....kindly help

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I had a similar issue. My solution is VBA code to construct an SQL and uses QueryDefs collection to modify an Access query object then export that query. I do that method because the criteria is more complex.

    Does your form have Access query object as RecordSource or is the RecordSource an sql statement? Is your filtering done by parameters in query that refer to comboboxes for input? I expect that a query object with parameters should work in your case. Do you want to export to a new or existing worksheet? Are you using TransferSpreadsheet method?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    gokul1242 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    5

    Export Filtered Listbox output to a Excel Sheet

    Quote Originally Posted by June7 View Post
    I had a similar issue. My solution is VBA code to construct an SQL and uses QueryDefs collection to modify an Access query object then export that query. I do that method because the criteria is more complex.

    Does your form have Access query object as RecordSource or is the RecordSource an sql statement? Is your filtering done by parameters in query that refer to comboboxes for input? I expect that a query object with parameters should work in your case. Do you want to export to a new or existing worksheet? Are you using TransferSpreadsheet method?
    Hi my filtering is done by parameters in query that refers to the combo box input only. And i am exporting the data to a new worksheet everytime.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    So what is not working? Do you have code? Why doesn't it work - error message, wrong results, nothing happens? Post code for analysis.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Save the query you are using as for the list box as a database object (an actual query) then just use the transferspreadsheet function to export that query. You don't need to export the list box (though it can be done) it'd be a little painful and way more time consuming than just exporting a query with the exact same setup as the rowsoure of the listbox. Then if you want to export to a differently named file each time you can use the parameters of your search to create it for instance

    dim sExportFilename as string


    sExportfilename = "c:\test\Exported_" & [SkillsArea] & "-" & [Skill] & ".xls"

    so your export name would end up being: Exported_Multi Language Skill_French.xls

    which you could then stick into your transferspreadsheet statement.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Export multiple query's to multiple sheet excel
    By vaikz in forum Import/Export Data
    Replies: 4
    Last Post: 08-15-2012, 08:53 AM
  2. Open Report filtered by Date in ListBox
    By TinaCa in forum Programming
    Replies: 1
    Last Post: 03-06-2012, 02:29 PM
  3. Export Filtered Results to Excel Tabs
    By opod in forum Programming
    Replies: 1
    Last Post: 08-03-2011, 01:33 PM
  4. Sub form filtered by listbox
    By BorisGomel in forum Forms
    Replies: 3
    Last Post: 05-04-2011, 09:20 AM
  5. Replies: 1
    Last Post: 04-17-2011, 04:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums