+ Reply to Thread
Results 1 to 21 of 21

One filter for 3 Queries in Union Query

  1. #1
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    One filter for 3 Queries in Union Query

    I currently have a union query with 3 queries linked to it. There is a “Start’ and “End” date filter for all three queries. The start and end date filters pop up three times(One for each query). I am trying to only get it to pop up once but to apply the filter to all three queries in the Query Union.

  2. #2
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: One filter for 3 Queries in Union Query

    Place two text boxes on a form and direct each set of query criterias to the text boxes (instead of the existing filters). Open the form, place the start and end dates in the text boxes, then run the union query.
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

  3. #3
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: One filter for 3 Queries in Union Query

    Thanks. I am fairly new to access so I might need a little additional help. So far, I created a form named DateFilter with two text boxes and named one dtStart and the other dtEnd. I then a where statement in each of the three queries under the date that is to be filtered. Should I create some kind of button in the form to execute the UNION query? Also is my where statement correct?

    "WHERE StartDate"="mm/dd/yyyy" & [Forms]![DateFilter].[dtStart] & "mm/dd/yyyy" And "EndDate"="mm/dd/yyyy" & [Forms]![DateFilter].[dtEnd] & "#"

  4. #4
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: One filter for 3 Queries in Union Query

    A button is a good idea.

    Just set the Startdate criteria in each query as [Forms]![DateFilter].[dtStart] and the EndDate criteria as [Forms]![DateFilter].[dtEnd]

  5. #5
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: One filter for 3 Queries in Union Query

    Thanks for the clarification. I just entered this inthe criteria of the Date field:

    Between [StartDate] And [EndDate] WHERE StartDate = #" & Forms!DateFilter.dtStart & "# AND EndDate = #" & Forms!DateFilter.dtEnd & "#"

    But it said there is an invalid syntax. I am trying to figure out what the error is. Thanks for your help

  6. #6
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: One filter for 3 Queries in Union Query

    Are you doing this in the source queries or the union query?

  7. #7
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: One filter for 3 Queries in Union Query

    I am doing them in the source queries. Is this correct?

  8. #8
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: One filter for 3 Queries in Union Query

    Yes. Are you using query design view, or SQL view?

  9. #9
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: One filter for 3 Queries in Union Query

    I am using query design view. Is this correct

  10. #10
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: One filter for 3 Queries in Union Query

    yes,

    For the StartDate field, the criteria line should have:

    Please Login or Register  to view this content.
    and the EndDate field criteria line should be:

    Please Login or Register  to view this content.
    nothing more.

  11. #11
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: One filter for 3 Queries in Union Query

    Thanks. I think my problem is that I only a DATE field. how could I break this down into start and end date and then point to the form? I think I might have missed a step. Thanks for the help.

  12. #12
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: One filter for 3 Queries in Union Query

    If you only have one date field, then try:

    Please Login or Register  to view this content.
    in the criteria line.

  13. #13
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: One filter for 3 Queries in Union Query

    that generates the query but it also displays a pop up for start and end 3 times(one for each query) I have the following in the date field criteria for all the queries

    Between [Forms]![DateFilter].[dtStart] And [Forms]![DateFilter].[dtEnd]

    Any ideas what might be causing the problem?

    Thanks

  14. #14
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: One filter for 3 Queries in Union Query

    Is the form open?

  15. #15
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: One filter for 3 Queries in Union Query

    yes the form is open and i created a button to run the UNION Query. Any ideas what the problem might be?

    Thanks

  16. #16
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: One filter for 3 Queries in Union Query

    Switch to SQL view in one of your source queries, copy the SQL, and post it here.

  17. #17
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: One filter for 3 Queries in Union Query

    This the UNION sql code. I have a command button on the form to generate this UNION query

    select * from application_final
    UNION
    select * from locked_final
    UNION select * from funded_final;

    Thanks

  18. #18
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: One filter for 3 Queries in Union Query

    And a source query?

  19. #19
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: One filter for 3 Queries in Union Query

    how would i get to source query? Thanks

  20. #20
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: One filter for 3 Queries in Union Query

    Open [application_final] in design view, then change the "view" button to SQL view.

  21. #21
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: One filter for 3 Queries in Union Query

    i figured it out, the query parameters were set to START and END. I removed them and it generates perfectly. thanks for all your help,

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1