Results 1 to 7 of 7
  1. #1
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77

    Cool How to export data whichever way user filters it on the form

    Hello,



    I have a form whose record source is a query combining employee data, QRY-EMPLOYEES.

    User will filter and sort this data mega-multiple ways on this form. A simple example: filtered for a single department and location, sorted by name.

    I have created an export button whose event on Click is to export to Excel. Simplest macro works great. Hooray! However, it ignores the user's filtering and sorting and just exports the entire record source QRY-EMPLOYEES.

    I'm thinking there's a simple way to say export just the data filtered, and as sorted. I couldn't possibly make a query for every single combination.

    Any help appreciated!

    Kay from Toronto

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You will likely have to build a SQL statement on the fly or have a separate query where the criteria are set by whatever is on your form and export the separate query/SQL statement. I suspect it would rather be the former than the latter but I don't know the complexity of your query or the data types.

  3. #3
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77
    I have another clue. If I just use the command from the ribbon [ External Data tab > Export Group > Excel ], it does export just what is filtered! So wouldn't that mean that there must be a simple VB statement for it? I've been searching for samples online. I think this must be a common request.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    That opens the Import/Export wizard and user can make choices.

    Open the wizard programmatically with:

    DoCmd.RunCommand acCmdExportExcel

    If you don't want the wizard, will have to be along what rpeare describes using TransferSpreadsheet method or other more complicated code.
    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
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77
    Thank you both, rpeare and June7! I think opening the wizard programmitically will work for my user group.

    I have been trying to avoid coding since I haven't coded for years and I'm building fairly simple dbs. This has come up a few times. I think I need a list of how to execute all the ribbon commands programmatically. I will search for one, but I don't suppose there's one somewhere on the forum and I just haven't stumbled across it yet?

    With regards, Kay

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by kattatonic1 View Post
    I will search for one, but I don't suppose there's one somewhere on the forum and I just haven't stumbled across it yet?

    With regards, Kay
    Docmd.RunCommand

    acCommand Enumeration
    http://msdn.microsoft.com/en-us/libr.../ff821354.aspx

    Also, if you want to get the current recordset of the form you can use RecordsetClone. This will include only the filtered results.

    something like
    dim rs as dao.recordset
    set rs = me.recordsetclone

    additionally, you can get the where clause from a form's filter by (I think)
    dim strFilter as string
    strFilter = Me.filter

    You can then pass the strFilter to a docmd.openreport where criteria

  7. #7
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77
    Hey ItsMe,

    That's perfect. I'll bookmark it and this also. I love this forum and you ppl!

    Kay

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

Similar Threads

  1. User entered optional filters
    By stevehoyle in forum Forms
    Replies: 7
    Last Post: 09-11-2013, 11:41 AM
  2. Export Form And Subform Data To Excel Form Same Worksheet
    By tomtheappraiser in forum Import/Export Data
    Replies: 6
    Last Post: 08-12-2013, 10:39 AM
  3. Replies: 5
    Last Post: 08-03-2012, 04:20 PM
  4. Export a form data with attachment
    By Gloring in forum Import/Export Data
    Replies: 1
    Last Post: 07-02-2012, 03:00 PM
  5. Export selected data from form
    By siedne in forum Forms
    Replies: 1
    Last Post: 12-01-2011, 05:48 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