Results 1 to 2 of 2
  1. #1
    rwest is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    5

    Filtering forms by date

    Hello Everyone,
    I'm creating a form in access that is connected with a table that has a date column as mm/dd/yyyy. I want to filter the form but just by the year. When I try to do this with the code I have nothing happens not even an error message. Below is the code that I have, any help on this would be greatly appreciated.
    Thanks
    Code:
    Private Sub FindYear_AfterUpdate()

    Me.FindYear = IIf(IsDate(Me.FindYear), _
    Format(Me.FindYear, " yyyy"), _
    "")


    Dim strFilter As String, strOldFilter As String

    strOldFilter = Me.Filter

    'txtFind - Date
    If Me.FindYear > "" Then _
    strFilter = strFilter & _
    " AND ([eventdatestart]=" & _


    Format(CDate(Me.FindYear), _
    "\#m/d/yyyy\#") & ")"
    If strFilter > "" Then strFilter = Mid(strFilter, 6)
    If strFilter <> strOldFilter Then
    Me.Filter = strFilter
    Me.FilterOn = (strFilter > "")
    End If
    End Sub

  2. #2
    Stingaway is offline Efficiency Junkie
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    The deep south. Keep going until you hit water basically.
    Posts
    224
    On this I would typically attach the form to a query and then filter it through the query instead of using code.

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

Similar Threads

  1. Filtering Forms
    By Iggsy in forum Forms
    Replies: 6
    Last Post: 11-23-2011, 01:01 AM
  2. Access 2007 Filtering Forms
    By mab in forum Forms
    Replies: 2
    Last Post: 05-20-2011, 06:14 AM
  3. Problem with filtering on DATE Variable
    By SIGMA248 in forum Programming
    Replies: 1
    Last Post: 04-01-2011, 10:33 AM
  4. Date Filtering problem
    By TubbyGrey in forum Access
    Replies: 6
    Last Post: 10-22-2010, 10:46 PM
  5. Combo Box Filtering between Forms
    By andrew_ww in forum Access
    Replies: 3
    Last Post: 12-30-2009, 11:06 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