Results 1 to 14 of 14
  1. #1
    justinwright is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    104

    Filtering Report based on date range (and prior dates)

    I found the thread about one specific date (and pbaldy's site) which was a huge help, but I was wondering two things.

    How do i filter a report based on a date range (controls on form)? txtDate1 and txtDate2




    The code I have opening the report with just a specific date is as follows:

    Code:
    DoCmd OpenReport "RefDueSpecifiedDate", acViewPreview, , "PENDDATE = #" & Me.txtDate1 & "#"
    And I want to incorporate for the range txtDate1 as the beginning date and txtDate2 as the ending date for the filter.

    The next question is, how would I structure a filter that will return (based on txtDate1) the current date and any dates prior to that AND have a null value for PROCESSED (or NO value for PROCESSED) field in the table?

  2. #2
    justinwright is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    104
    Sorry about the double post, but I feel happy to be able to post the answer for others that I worked out

    At the top of the private sub I put this:

    Code:
    Dim strReport as String
    Dim strDateField as String
    Dim strWhere As String
    Const strcDateConst = "\#mm\/dd\/yyy\#"
    To define the variables for use

    Then put the following code in the proper if statement:

    Code:
    strReport = "EntrySpecificDateRange" 'report name
    strDateField = "[DATEENTRY]" 'field name here
    
    'Make filter string
    If Isdate(Me.txtDate1) Then
        strWhere = "(" & strDateField & " >= " & Format(Me.txtDate1, strcDateConst) & ")"
    End If
    
    If IsDate(Me.txtDate2) Then
        If strWhere <> vbNullString Then
            strWhere = strWhere & " AND "
        End If
        strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtDate2 + 1, strcDateConst) & ")"
    End If
    
     'Open Report
    DoCmd.OpenReport strReport, acViewPreview, , strWhere
    ' acViewNormal for printing, acViewPreview for previewing
    It seems like that makes the date range work fine, but how do I add something to check for the PROCESSED value as Null and NO?

    How do I take txtDate1 and return all that dates and the date before where PROCESSED is Null or has a NO value?

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The Query builder know how to do all of this. Have you tried using it yet? If the Criteria is on the same row then it is an AND, and if you put it on a different Criteria Row then it is an OR. Post back here if you need further assistance.

  4. #4
    justinwright is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    104
    Well the only problem is that I don't have the first clue about queries.

    I created one withboth :
    Filter: PENDDATE PROCESSED
    Table: TrackingTable TrackingTable
    Sort:
    Show: (Checked) (Checked)
    Criteria =[Form]![RepFrm]![txtTodaysDate] ="No"
    or: <[Form]![RepFrm]![txtTodaysDate]


    but in reality I have no remote clue whatsoever what I'm doing when it comes to queries. That's probably so far off the mark it isn't even funny, which is why I wanted to see if there was a way I could do it in VBA.

    Thanks for the help though.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Start by switching to SQL view and post what is there.

  6. #6
    justinwright is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    104
    SELECT TrackingTable.PENDATE, TrackingTable.PROCESSED
    FROM TrackingTable
    WHERE(((TrackingTable.PENDDATE)=[Form]![RepFrm]![txtTodaysDate])AND ((TrackingTable.PROCESSED)="No")) OR (((TrackingTable.PENDDATE)<[Form]![RepFrm]![txtTodaysDate]));

  7. #7
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Justin,

    for further help on dates, you may want to check out my dates page: http://www.ajenterprisesonline.com/ab/_dates/

    I didn't read through this entire thread, but some of the things that people ask about dates can be solved by using that page. Just for reference...

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    So you just want those two fields in your recordset?

  9. #9
    justinwright is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    104
    Yeah, I'm just looking to filter a report based on dates equal to and before txtTodaysDate (PENDDATE) that also have a No value for the PROCESSED field

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    But your report wants all of the fields in the table right? You are only handing the report those two fields.

  11. #11
    justinwright is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    104
    Oh, so I put no criteria for the other fields that I want on the report (but still include them in the query)?

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Bingo! All of the fields for your report need to be puulled by your query and displayed. You do not need to display the fields with the selection criteria if you don't want to. You can have the same field listed twice with different criteria in each column and depending on whether the criteria is on the same row or a different row dictates AND or OR.

  13. #13
    justinwright is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    104
    Okay so I was totally lost with Queries, but thankfully I figured it out for VBA in case anyone was interested:

    Code:
    Dim strWhere As String
    ' Define variable for use
    At top, then in the appropriate if statement:

    Code:
    If Me.cboRefunds.Value = "Today" Then
        ' Needs to incorporate the current day and any that are outstanding (past due date but not processed)
        
        strWhere = "[PROCESSED] = '" & "No" & "' AND PENDDATE <= #" & Me.txtTodaysDate & "#"
        
        DoCmd.OpenReport "RefDueCurrentDay", acViewPreview, , strWhere
    Thank you for the help though, as always

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I like teaching people to fish rather than cooking a meal. Excellent!

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

Similar Threads

  1. Define a date range for a report - Help
    By Optimus_1 in forum Access
    Replies: 4
    Last Post: 06-02-2010, 04:50 AM
  2. Filtering Report with between dates
    By patrickmcdiver in forum Reports
    Replies: 3
    Last Post: 02-22-2010, 12:11 PM
  3. Replies: 3
    Last Post: 09-29-2009, 07:08 AM
  4. Replies: 0
    Last Post: 07-27-2009, 07:51 AM
  5. Count Dates within Date Range
    By eckert1961 in forum Queries
    Replies: 2
    Last Post: 03-08-2009, 10:58 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