Results 1 to 3 of 3
  1. #1
    ARickert's Avatar
    ARickert is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Location
    Kansas
    Posts
    22

    Filter Report by Optional Date and Optional Combo Box

    I posted this on the SQL forum and no one gave me any helpful advice. I'd like to reiterate that I'M A NOVICE; I need this explained so I can understand it, and apply it.


    The code below was someone elses that I adapted to my databse.

    I would like to filter Report: DQC by an OPTIONAL date range (which I have done with the code below). I would also like to filter it by and OPTIONAL combo box that self populates from my table with PEBLO names. I have gotten the combo box to self populate, but do not know how to add it into the VB. Combo Box Name: Combo27

    Code:
    Private Sub Command29_Click()
    Dim strReport As String
    Dim strDateField As String
    Dim strWhere As String
    Dim lngView As Long
    Const strcJetDate = "\#mm\/dd\/yyyy\#" 
    
    strReport = "DQC" 
    strDateField = "[Date]" 
    lngView = acViewPreview 
    
    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
    
    
    If CurrentProject.AllReports(strReport).IsLoaded Then
    DoCmd.Close acReport, strReport
    End If
    
    '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

  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
    Quote Originally Posted by ARickert View Post
    no one gave me any helpful advice. I'd like to reiterate that I'M A NOVICE; I need this explained so I can understand it, and apply it.

    I find that somewhat offensive, since I believe I gave you the correct direction to go in on the other thread. What exactly about your existing code do you need explained so that the advice given previously makes sense to you?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ARickert's Avatar
    ARickert is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Location
    Kansas
    Posts
    22
    PBaldy, I wasn't trying to be offensive, that's why I stressed that I'm a novice... I don't understand what you are talking about. I'm not saying your advice wasn't right, I just don't understand it.

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

Similar Threads

  1. Filter Report by Optional Date Range and Combo Box
    By ARickert in forum SQL Server
    Replies: 3
    Last Post: 10-17-2012, 10:46 AM
  2. Optional filtering (was More questions..)
    By Daryl2106 in forum Access
    Replies: 17
    Last Post: 09-21-2012, 07:12 PM
  3. multiple optional criteria
    By TheShabz in forum Programming
    Replies: 7
    Last Post: 07-05-2011, 05:13 PM
  4. SQL query with an optional date field
    By StevenBee in forum Programming
    Replies: 1
    Last Post: 05-30-2011, 02:40 PM
  5. Skipping optional arguments
    By canfish in forum Programming
    Replies: 3
    Last Post: 08-19-2010, 01:35 PM

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