Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    bbarclay is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    17

    Allen Browns Date Range + Combo Box for Client and Project Report Filter Coding Help

    Date range works great even after adding my code. But I still can't get the combo boxes labeled "txtClient" to filter out the Client section of the report based on the criteria. // I've added this code //

    Code:
      If Not IsNull(Me.txtClient) Then
            strWhere = strWhere & "([Client] = " & Me.txtClient & ") AND "
        End If
    But still can't get it to work. Any suggestions please.

    Here is the full code I'm using for this process.

    Thanks for any help

    Brandon



    Code:
    Private Sub cmdPreview_Click()
    'On Error GoTo Err_Handler      'Remove the single quote from start of this line once you have it working.
        'Purpose:       Filter a report to a date range.
        'Documentation: http://allenbrowne.com/casu-08.html
        'Note:          Filter uses "less than the next day" in case the field has a time component.
        Dim strReport As String
        Dim strDateField As String
        Dim strWhere As String
        Dim lngView As Long
        Const strcJetDate = "\#mm\/dd\/yyyy\#"  'Do NOT change it to match your local settings.
        
        'DO set the values in the next 3 lines.
        strReport = "Payment_Due_Date"      'Put your report name in these quotes.
        strDateField = "[Payment_Due_Date]" 'Put your field name in the square brackets in these quotes.
        lngView = acViewPreview     'Use acViewNormal to print instead of preview.
        
        
        'Build Combo Filter
        
            If Not IsNull(Me.txtClient) Then
            strWhere = strWhere & "([Client] = " & Me.txtClient & ") AND "
        End If
        
        'Build the filter string.
        If IsDate(Me.txtStartDate) Then
            strWhere = "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
        End If
        If IsDate(Me.txtEndDate) Then
            If strWhere <> vbNullString Then
                strWhere = strWhere & " AND "
            End If
            strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
        End If
        
        'Close the report if already open: otherwise it won't filter properly.
        If CurrentProject.AllReports(strReport).IsLoaded Then
            DoCmd.Close acReport, strReport
        End If
        
        'Open the report.
        'Debug.Print strWhere        'Remove the single quote from the start of this line for debugging purposes.
        DoCmd.OpenReport strReport, lngView, , strWhere
    
    Exit_Handler:
        Exit Sub
    
    Err_Handler:
        If Err.Number <> 2501 Then
            MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
        End If
        Resume Exit_Handler
    End Sub


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What does the Debug.Print line result in? What is the data type of client?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    bbarclay is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    17
    Doesn't return anything just goes to the report but doesn't filter. The datatype is going to be text. Though i added this code to my report and it's returning a number, which I believe is the ID from the combobox. =[Forms].[frmWhatDates].[txtClient] // That will return a number instead of George, Frank or Tim.

  4. #4
    bbarclay is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    17
    // More info// The field that is in the report is SELECT [Client].[ID], [Client].[Client], Client.[project_lookup] FROM Client; // The combo box is this. SELECT Client.ID, Client.Client FROM Client; // So it's trying to pass the id to filter, but being that the report field is by ID i think that it's not trying to pass text but a key value like.... 1, 2, 3, 4. Then it would display the name.

  5. #5
    bbarclay is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    17
    // if i do a seperate button. and do the following code, it will filter out client.

    Code:
    Private Sub Command13_Click()
    DoCmd.OpenReport "Payment_Due_Date", acPreview, , " [Client] = " & Me.[txtClient]
    End Sub

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What I meant was to uncomment this line:


    Debug.Print strWhere

    and post here what gets output to the Immediate window. That will tell us what the final string is, and we can compare it to what you expect.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    bbarclay is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    17
    K, i tried this and nothing pops up. Shouldn't there be a popu that tells me what it's for. That's not happening.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It goes to the VBA Immediate window:

    http://www.baldyweb.com/ImmediateWindow.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    bbarclay is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    17
    ([Payment_Due_Date] >= #01/02/2012#) AND ([Payment_Due_Date] < #09/07/2012#)

  10. #10
    bbarclay is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    17
    Fixed it. Here's what i did. I put that code at the bottom added AND to the date code like this.
    Code:
        'Build the filter string.
        If IsDate(Me.txtStartDate) Then
            strWhere = "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
        End If
        If IsDate(Me.txtEndDate) Then
            If strWhere <> vbNullString Then
                strWhere = strWhere & " AND "
            End If
            strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ") AND"
        End If
        
       If Not IsNull(Me.txtClient) Then
            strWhere = strWhere & "([Client] = " & Me.[txtClient] & ")"
        End If

  11. #11
    bbarclay is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    17
    Thank you for you help. Using Immediate window helped me to realize that my strWhere was not passing through the client information.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    ARickert's Avatar
    ARickert is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Location
    Kansas
    Posts
    22

    Unhappy Same Problem

    [QUOTE=bbarclay;117878]
    Code:
    If Not IsNull(Me.txtClient) Then
    strWhere = strWhere & "([Client] = " & Me.[txtClient] & ")"
    End If
    I am having the same problem getting a combo box to function as another alternate filter to my report. you said you had fixed it by added the above to the end of your SLQ, but this isn't working for me, and I'm not sure what I'm doing wrong. Can you eleaborate? When I put that in for mine I go to debugging.

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What is your code?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    ARickert's Avatar
    ARickert is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Location
    Kansas
    Posts
    22
    Code:
    Private Sub Command29_Click()
    'On Error GoTo Err_Handler      'Remove the single quote from start of this line once you have it working.
        'Purpose:       Filter a report to a date range.
        'Documentation: http://allenbrowne.com/casu-08.html
        'Note:          Filter uses "less than the next day" in case the field has a time component.
        Dim strReport As String
        Dim strDateField As String
        Dim strWhere As String
        Dim lngView As Long
        Const strcJetDate = "\#mm\/dd\/yyyy\#"  'Do NOT change it to match your local settings.
        
        'DO set the values in the next 3 lines.
        strReport = "DQC"      'Put your report name in these quotes.
        strDateField = "[Date]" 'Put your field name in the square brackets in these quotes.
        lngView = acViewPreview     'Use acViewNormal to print instead of preview.
        
        'Build the filter string.
        If IsDate(Me.Text22) Then
            strWhere = "(" & strDateField & " >= " & Format(Me.Text22, strcJetDate) & ")"
        End If
        If IsDate(Me.Text24) Then
            If strWhere <> vbNullString Then
                strWhere = strWhere & " AND "
            End If
            strWhere = strWhere & "(" & strDateField & " < " & Format(Me.Text24 + 1, strcJetDate) & ")"
           End If
        
        'Close the report if already open: otherwise it won't filter properly.
        If CurrentProject.AllReports(strReport).IsLoaded Then
            DoCmd.Close acReport, strReport
        End If
            
        'Open the report.
        'Debug.Print strWhere        'Remove the single quote from the start of this line for debugging purposes.
         DoCmd.OpenReport strReport, lngView, , strWhere
        
    Exit_Handler:
        Exit Sub
    Err_Handler:
        If Err.Number <> 2501 Then
            MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
        End If
        Resume Exit_Handler
    End Sub
    Private Sub RUN_Click()
    End Sub
    I want to add in that if a PEBLO is chosen from Combo27 that it ALSO filters through there. But whenever I add AND" to the end of this code I get a debug for this line: DoCmd.OpenReport strReport, lngView, , strWhere

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multiple Field & date range filter
    By mrkandohi001 in forum Reports
    Replies: 6
    Last Post: 01-18-2012, 03:11 AM
  2. Code to combine report filter and date range
    By rhubarb in forum Reports
    Replies: 17
    Last Post: 10-28-2011, 03:08 PM
  3. Filter to a date range ala Allen Brown
    By kekawaka in forum Forms
    Replies: 2
    Last Post: 10-10-2011, 12:19 PM
  4. Project, time, client, contact tracking
    By windwardmi in forum Database Design
    Replies: 2
    Last Post: 07-04-2011, 05:18 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