Results 1 to 4 of 4
  1. #1
    dfaulkner1 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Posts
    5

    Auto Splitting a query using VB code


    Hi

    I was hoping somebody could help me, I'm struggling to get my database to auto split up a Query by a certain Column and automatically get it to export into separate Excel files.

    I have got the export sorted, currently set to export the whole query, but i'm struggling to do the splitting up, does anybody have a piece of script they know works for this?

    Thanks
    Dan

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Is it always the same fields for export - same 'split'? What export method are you using? I expect you will need two queries.
    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
    dfaulkner1 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Posts
    5
    Here is an example of the data I'm trying to export:

    Led Acc
    1 1blah
    1 1okhi
    4 4high
    5 5cmd1

    What I'm trying to do is get it split up by the "Led" field, so you would have a .xlsx file with just the led 1 accounts on, another with the just the led 4 etc.

    Here is what I'm currently using to export all into just one file
    DoCmd.OutputTo acOutputQuery, "Newly_created_accounts", acFormatXLSX, "\\buzz2\Office on Buzz2\Newonlineusers\test1.xlsx"
    DoCmd.Close acQuery, "Newly_created_accounts", acSaveNo

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Then you need to apply filter criteria. Options for modifying query filter criteria:

    1. dynamic parameters in query - either popups (I NEVER use) or reference to controls on form

    2. export a report based on query - can be dynamic parameterized query http://www.datapigtechnologies.com/f...mtoreport.html or apply filter criteria to report when it is opened using the WHERE CONDITION argument of OpenReport method

    3. VBA code that modifies query using QueryDefs

    How many Led values are there? I expect will need to open a recordset of the Led values, loop through recordset, somehow set the query filter parameter with value, export query, move to next Led record, repeat.
    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.

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

Similar Threads

  1. Replies: 1
    Last Post: 07-23-2015, 05:11 AM
  2. Replies: 2
    Last Post: 04-14-2015, 07:21 AM
  3. Splitting Data Using A Scanned Bar-code Entry
    By euphonium01 in forum Forms
    Replies: 4
    Last Post: 03-24-2014, 11:32 AM
  4. Splitting DBase query
    By GraemeG in forum Access
    Replies: 0
    Last Post: 03-28-2011, 02:48 PM
  5. When I select name code appear auto
    By miziri in forum Forms
    Replies: 0
    Last Post: 03-09-2010, 02:10 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