Results 1 to 9 of 9
  1. #1
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Unbound Combobox Filter By Date Criteria

    I have a unbound combobox on my form that I need to filter by date range. I am using a Value List as the record source.
    The combobox is name Combo63 and here is it's Row Source: It is a Value List
    The Date I wish to use as the criteria is a date field with NO format assigned and no input mask. EventStart is the control date field.


    "All";"Today";"This Week";"Last Week";"This Month";"Last Month";"Next Month"


    How can I filter the form with this criteria?

    Here is all my code to try and do it. Of course I get an error with so?..

    If [Forms]![frmEvent]![Filter]="Today" Then
    (Year([nextschddte])=Year(Date()) And Month([nextschddte])=Month(Date()) And Day([nextschddte])=Day(Date()))

    If [Forms]![frmEvent]![Filter]="This Week"
    (Year([nextschddte])=Year(Date()) And DatePart("ww",[nextschddte],0)=DatePart("ww",Date(),0))

    If [Forms]![frmEvent]![Filter]="Last Week"
    (Year([nextschddte])=Year(Date()) And Month([nextschddte])=Month(Date()))

    If [Forms]![frmEvent]![Filter]="Last Month" Then
    (Year([nextschddte])=Year(Date()) And Month([nextschddte])=(Month(Date())-1))

    If [Forms]![frmEvent]![Filter]="Next Month".
    (Year([nextschddte])=Year(Date()) And Month([nextschddte])=(Month(Date())+1))



    If [Forms]![frmEvent]![Filter]="All"
    DoCmd.ShowAllRecords
    Last edited by burrina; 01-03-2013 at 11:37 PM. Reason: My Code:

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Try:

    Select Case Me.Combo63
    Case "Today"
    Me.Filter = "[nextschddte]=Date()"
    Case "This Week"
    Me.Filter="[nextschddte] BETWEEN Date()-7 AND Date()"
    Case "Last Week"
    Me.Filter="[nextschddte] BETWEEN Date()-14 AND Date()-7"
    Case "Last Month"
    Me.Filter="Month([nextschddte]) & Year([nextschddte]) = Month(Date()-1 & Year(Date())"
    Case "Next Month"
    Me.Filter="Month([nextschddte]) & Year([nextschddte]) = Month(Date()+1 & Year(Date())"
    Case "All"
    DoCmd.ShowAllRecords
    End Select
    Me.FilterOn
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    It does not like that Me.FilterON I put the code on the OnClickEvent, is this correct?
    Last edited by burrina; 01-04-2013 at 01:11 AM. Reason: sorry, it's working Had to put FilterOn = True

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Good catch, sorry for slip up. Glad it worked otherwise.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Thanks Again.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Another oops. The Last and Next Month probably won't work if crosses years. Try instead:

    Case "Last Month"
    Me.Filter="Month([nextschddte]) & Year([nextschddte]) = Month(DateAdd("m",-1,Date())) & Year(DateAdd("m",-1,Date()))"
    Case "Next Month"
    Me.Filter="Month([nextschddte]) & Year([nextschddte]) = Month(DateAdd("m",+1,Date())) & Year(DateAdd("m",+1,Date()))"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    picture of error

    syntax error with that, don't know what it is???
    Attached Thumbnails Attached Thumbnails datecodeerror.jpg  
    Last edited by burrina; 01-04-2013 at 01:40 AM. Reason: picture

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Rats, try apostrophes instead of quotes around "m".

    Another version:

    ="Format([nextschddte],'mmyyyy') = Format(DateAdd('m',-1,Date()),'mmyyyy')"

    ="Format([nextschddte],'mmyyyy') = Format(DateAdd('m',+1,Date()),'mmyyyy')"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Yep, no errors this time.. Thank You.

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

Similar Threads

  1. Filter Using ComboBox For Date Criteria
    By burrina in forum Forms
    Replies: 12
    Last Post: 11-29-2012, 08:02 PM
  2. Replies: 1
    Last Post: 09-06-2011, 01:47 PM
  3. Apply Filter based on unbound date boxes
    By anoob in forum Access
    Replies: 3
    Last Post: 01-21-2011, 05:26 PM
  4. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  5. Replies: 0
    Last Post: 12-16-2009, 01:14 PM

Tags for this Thread

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