Results 1 to 4 of 4
  1. #1
    database_1 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2020
    Posts
    34

    Date filter query problem


    I have a search query where the user can filter the options machine, area of the machine, and before and after date. So far every filter works fine but the query does not show all results on the form opening. It looks like the date criteria causes this. I have the criteria code, Between [Forms]![SEARCH_FRM_2]![TXT_AFTER] And [Forms]![SEARCH_FRM_2]![TXT_BEFORE]. I thought putting Is Null in the Or row would help but it did not. If you can help me show all results at the beginning of the search, that would be greatly appreciated. Thank you.

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Are you dynamically building the query based on the search form or is this a static query?

    Can you post the rest of the sql and/or code you're using?

    Can you elaborate on "the query does not show all results on the form opening"? This implies that it eventually loads the results you're after?

    This may or may not be useful to you: http://allenbrowne.com/ser-62.html

  3. #3
    database_1 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2020
    Posts
    34
    So I have a form that an employee fills out and that data is added to a table. The boss can then go into another form with a subform query in it. This form has comboboxes that filter information plus two text boxes for before and after dates. These filters are applied with an "apply" button that updates the query. I want it so when the boss goes to the "search" form, he sees every option available. Then from there, he can filter the options however they want using the comboboxes or date boxes. The combobox options and date option do filter the form correctly but nothing shows on the query until you put a before and after date. I want the user to be able to just filter by machine if they want, and not require them to input a date. I hope I explained it a little better. I will also include my whole SQL statement but it is definitely the date criteria that is causing this error.
    SELECT DISTINCT ACTION_TBL.Date, MACH_TBL.MACHINE, AREA_TBL.MACH_AREA, ITEM_TBL.ITEM, ACTION_TBL.MACH_AREA_ID, ITEM_TBL.ITEM_ID, ACTION_TBL.[DOWN TIME], ACTION_TBL.EVENT, ACTION_TBL.[CORRECTIVE ACTION], ACTION_TBL.[EFFECTED PALLET], ACTION_TBL.AUDIT_PERF, ACTION_TBL.HELDWARE, ACTION_TBL.[SCAR#], ACTION_TBL.SHIFT
    FROM TIME_TBL, ITEM_TBL INNER JOIN (MACH_TBL INNER JOIN (AREA_TBL INNER JOIN ACTION_TBL ON AREA_TBL.MACH_AREA_ID = ACTION_TBL.MACH_AREA_ID) ON MACH_TBL.MACH_ID = ACTION_TBL.MACH_ID) ON ITEM_TBL.ITEM_ID = ACTION_TBL.ITEM_ID
    WHERE (((ACTION_TBL.Date) Between [Forms]![SEARCH_FRM_2]![TXT_AFTER] And [Forms]![SEARCH_FRM_2]![TXT_BEFORE]) AND ((ACTION_TBL.MACH_AREA_ID) Like "*" & [Forms]![SEARCH_FRM_2]![AREA_COM2] & "*") AND (([ACTION_TBL]![MACH_ID]=[Forms]![SEARCH_FRM_2]![MACH_COM2] Or [Forms]![SEARCH_FRM_2]![MACH_COM2] Is Null)<>False));

  4. #4
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Take a look at this example that I posted before: http://allenbrowne.com/ser-62.html

    The way I would do this is to set your subform recordsource to the query WITHOUT any search criteria, this will initialize the subform with all of the data. Then when the user clicks the "apply" button you would use a series of if statements to dynamically build your filter in a string variable, if the date textboxes are blank then skip that part of the filter all together. Then you set your subform's filter property = to the string you just created, then turn on the subforms filter.

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

Similar Threads

  1. Replies: 2
    Last Post: 03-06-2019, 06:46 AM
  2. Adding a Date filter to SQL Query
    By bishmedia in forum Queries
    Replies: 15
    Last Post: 09-26-2018, 04:39 AM
  3. Filter by date in Query
    By Stan 2314 in forum Queries
    Replies: 3
    Last Post: 05-04-2013, 02:56 PM
  4. Query/Filter by Date
    By jasonbarnes in forum Reports
    Replies: 6
    Last Post: 01-04-2012, 04:05 PM
  5. Date Range filter in a Duplicate query
    By knickolyed in forum Forms
    Replies: 0
    Last Post: 06-27-2011, 04:56 AM

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