Results 1 to 3 of 3
  1. #1
    swalsh84 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    36

    Query for Received and Closed Date Range


    I built a report request menu to dynamically build a SQL query for Access to run a report. The user selects the parameters and the form builds the query on the fly and then changes the record set for the report to pull the right data.

    The query building was coming along swimmingly until the users requested a date range. I have a date range selection that can look at any cases within the date range. This part is not working currently. This is what the form generates. Get all cases with these specific parameters within this date range.

    SELECT qry_All_Records.* FROM qry_All_Records
    WHERE (CompanyCode Like '*' Or CompanyCode Is Null)
    AND (ResponsiblePerson Like '*' Or ResponsiblePerson Is Null)
    AND (CaseType Like '*' Or CaseType Is Null)
    AND (LPSStatus Like '*' Or LPSStatus Is Null)
    AND (Division Like '*' Or Division Is Null)
    AND (ProductLine Like '*' Or ProductLine Is Null)
    AND (CaseStatus IN('Closed','Open','Other','Pending - Legal','Pending - Production','Pending - Quality Review'))
    AND (BusinessLine Like '*' Or BusinessLine Is Null)
    AND (Source Like '*' Or Source Is Null)
    AND (SourceDetail Like '*' Or SourceDetail Is Null)
    AND ([ReceivedDate] Between #09/01/11# AND #09/30/11# OR [ClosedDate] Between #09/01/11# AND #09/30/11#)

    The problem ends up being that I get cases with received dates within the range and closed dates outside of the range or vice versa.

    1. Does this make sense?
    2. Any thoughts on how to fix this?


    Thanks,

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,618
    Yes, that does make sense. The query is returning exactly what is asked for. If you want records where the RecievedDate is between the range and ClosedDate is also between the range, then change the OR to AND.
    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
    swalsh84 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    36
    Slightly different approach approach. Basically what I wanted to accomplish is that if the case is not closed, then look at the received date only and get all cases within the date range. If the case is closed, get all cases that were closed within the date range and disregard the received date. This was accomplished successfully with the below query.

    SELECT qry_All_Records.* FROM qry_All_Records
    WHERE (CompanyCode Like '*' Or CompanyCode Is Null)
    AND (ResponsiblePerson Like '*' Or ResponsiblePerson Is Null)
    AND (CaseType Like '*' Or CaseType Is Null)
    AND (LPSStatus Like '*' Or LPSStatus Is Null)
    AND (Division Like '*' Or Division Is Null)
    AND (ProductLine Like '*' Or ProductLine Is Null)
    AND (CaseStatus IN('Closed','Open','Other','Pending - All Other Servicing','Pending - Default','Pending - ERC','Pending - Legal','Pending - Production','Pending - Quality Review'))
    AND (BusinessLine Like '*' Or BusinessLine Is Null)
    AND (Source Like '*' Or Source Is Null)
    AND (SourceDetail Like '*' Or SourceDetail Is Null)
    AND ((([ReceivedDate] BETWEEN #09/01/11# AND #09/30/11#) AND [ClosedDate] Is Null)
    OR ([ClosedDate] BETWEEN #09/01/11# AND #09/30/11#))

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

Similar Threads

  1. Replies: 4
    Last Post: 08-17-2011, 05:30 AM
  2. Run query by date range
    By ARickert in forum Access
    Replies: 2
    Last Post: 06-23-2011, 10:54 AM
  3. Complicated Query needs some date range help
    By KevinMCB in forum Queries
    Replies: 1
    Last Post: 01-11-2011, 12:25 PM
  4. Date range query from form
    By Steve Barnes in forum Queries
    Replies: 2
    Last Post: 07-29-2010, 07:06 PM
  5. Query for date range from two column?
    By sunny in forum Queries
    Replies: 2
    Last Post: 07-28-2010, 07:12 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