Results 1 to 3 of 3
  1. #1
    the_reg is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    8

    Working & Filtering Dates

    Hi Guys - i am trying to filter on a date 'txtDateSpudded' entered within a multi field input Form to display those results greater than the date entered ... i am having no luck getting this to work - please could someone help - thank you in advance
    Private Function BuildFilter() As Variant
    Dim varWhere As Variant
    Dim tmp As String
    Dim cmbGeographic_Region As String
    Dim cmbCountry As String

    Dim strReport As String
    Dim strDateField As String
    Dim strWhere As String
    Const strcDateConst = "\#mm\/dd\/yyy\#"

    strDateField = "[DateSpudded]" ' field name for Date

    tmp = """"


    varWhere = Null ' Main filter
    'varColor = Null ' Subfilter used for colors
    ' Check for Country
    If Len(Me.cmbCountry) > 0 Then
    varWhere = varWhere & "[Country] LIKE " & tmp & Me.cmbCountry & tmp & " AND "
    End If

    ' Check for Company
    If Len(Me.txtCompany) > 0 Then
    varWhere = varWhere & "[Company] LIKE " & tmp & Me.txtCompany & tmp & " AND "
    End If

    ' Check for Geographic Region
    If Len(Me.cmbGeographic_Region) > 0 Then
    varWhere = varWhere & "[Geographic_Region] LIKE " & tmp & Me.cmbGeographic_Region & tmp & " AND "
    End If
    ' Filter on Date
    If IsDate(Me.txtDateSpudded) Then
    varWhere = "(" & strDateField & " >= " & Format(Me.txtDateSpudded, strcDateConst) & ")" & " AND "
    End If

    If Len(Me.txtCompany) > 0 Then
    varWhere = varWhere & "[Company] LIKE " & tmp & Me.txtCompany & tmp & " AND "
    End If
    If Len(Trim(varWhere)) > 0 Then
    varWhere = Left(varWhere, Len(varWhere) - 5)
    End If
    BuildFilter = varWhere
    End Function

  2. #2
    the_reg is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    8
    i manged to get the date to be recognised work with the amended code below ... but still wont filter the records !!!


    Private Function BuildFilter() As Variant
    Dim varWhere As Variant
    Dim tmp As String
    Dim cmbGeographic_Region As String
    Dim cmbCountry As String

    Dim strReport As String
    Dim strDateField As String
    Dim strWhere As String
    Const strcDateConst = "mm/dd/yyyy" '"\mm\/dd\/yyy\"

    strDateField = "[DateSpudded]" ' field name for Date

    tmp = """"
    varWhere = Null ' Main filter
    'varColor = Null ' Subfilter used for colors
    ' Check for Country
    If Len(Me.cmbCountry) > 0 Then
    varWhere = varWhere & "[Country] LIKE " & tmp & Me.cmbCountry & tmp & " AND "
    End If

    ' Check for Company
    If Len(Me.txtCompany) > 0 Then
    varWhere = varWhere & "[Company] LIKE " & tmp & Me.txtCompany & tmp & " AND "
    End If

    ' Check for Geographic Region
    If Len(Me.cmbGeographic_Region) > 0 Then
    varWhere = varWhere & "[Geographic_Region] LIKE " & tmp & Me.cmbGeographic_Region & tmp & " AND "
    End If
    ' Filter on Date
    If IsDate(Me.txtDateSpudded) Then
    varWhere = "(" & strDateField & " >= " & Format(Me.txtDateSpudded, strcDateConst) & ")"
    End If

    If Len(Me.txtCompany) > 0 Then
    varWhere = varWhere & "[Company] LIKE " & tmp & Me.txtCompany & tmp & " AND "
    End If
    If Len(Trim(varWhere)) > 0 Then
    varWhere = Left(varWhere, Len(varWhere))
    End If
    BuildFilter = varWhere
    End Function

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use this to see the finished string:

    http://www.baldyweb.com/ImmediateWindow.htm

    i don't think it's going to look like you expect.

    also, date values should be surrounded by #.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 07-25-2013, 11:35 PM
  2. Filtering based on form dates
    By cbh35711 in forum Programming
    Replies: 3
    Last Post: 03-13-2012, 11:46 AM
  3. Filtering Dates Error!
    By emilyrogers in forum Forms
    Replies: 3
    Last Post: 02-15-2011, 03:00 AM
  4. Replies: 13
    Last Post: 09-27-2010, 03:10 PM
  5. Filtering Report with between dates
    By patrickmcdiver in forum Reports
    Replies: 3
    Last Post: 02-22-2010, 12:11 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