Results 1 to 5 of 5
  1. #1
    Pardysound is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2022
    Posts
    9

    Filter a form using Combo boxes with year and/or Month

    Hello, I have a form based on a query of a table that contains a date field. the query has calculated fields based on the datefield [EventDate] one that just shows the year "yyyy" and onthe that just shows the month "mmmm"



    I have 2 unbound combo boxes in the header I would like to use to filter the form.

    The the row source for each combo box is a Select statement that show the distinct Years and Months respectively using Format(EventDate,"yyyy") and Format(EventDate,"mmmm")

    The result I am looking for is if both combo boxes are blank then there is no filter applied, if there is a year selected the show all dates from that year, if there year and month seleced show dates from the year and month, if only a month is selected then show dates from any year in that month.

    Ive tried to use as the criteria:

    IIf(IsNull([Forms]![frmEventDateList]![cmbMonth]),"LIKE ""*""",[Forms]![frmEventDateList]![cmbMonth])
    IIf(IsNull([Forms]![frmEventDateList]![cmbYear]),"LIKE ""*""",[Forms]![frmEventDateList]![cmbYear])

    thinking that if the cobo box was blank it would plug LIKE "*" but that doesn't work.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,859
    Use OR Control Name is Null as additional criteria
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Pardysound is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2022
    Posts
    9
    Hi Thanks for the reply..

    I'm not sure how that helps... cmbMonth is the the control.. so I'm already testing it for Null no ?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    The operator (LIKE) cannot be within quote marks. Doing so just makes it literal text, not a keyword in the SQL.

    LIKE IIf(IsNull([Forms]![frmEventDateList]![cmbMonth]), "*", [Forms]![frmEventDateList]![cmbMonth])

    LIKE IIf(IsNull([Forms]![frmEventDateList]![cmbYear]), "*", [Forms]![frmEventDateList]![cmbYear])

    or

    LIKE Nz([Forms]![frmEventDateList]![cmbMonth], "*")

    LIKE Nz([Forms]![frmEventDateList]![cmbYear], "*")
    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
    Pardysound is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2022
    Posts
    9
    SOLVED!! thanks this is exactly what I needed to do.

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

Similar Threads

  1. Replies: 2
    Last Post: 07-06-2017, 02:28 AM
  2. Replies: 4
    Last Post: 05-19-2017, 06:20 AM
  3. Month/Year Filter on Continuous Form
    By doyouwantabedbath in forum Forms
    Replies: 1
    Last Post: 03-17-2016, 01:47 PM
  4. Filter Form records By Month Year
    By maxmaggot in forum Forms
    Replies: 4
    Last Post: 04-05-2013, 06:34 PM
  5. Replies: 9
    Last Post: 12-02-2011, 12:51 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