Results 1 to 8 of 8
  1. #1
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63

    Setting Query Criteria using Iif Statement


    Good afternoon,

    I currently have a query and a form. The form has three radio buttons (ListeningReviewOption, TargetReviewOption, and BothOption). I am attempting to set the criteria in a query based on the radio option the user selects in the form. If they select ListeningReviewOption, I want the criteria to show "Listening Review". If they select TargetReviewOption, I want the criteria to show "Target Review". I can do both of those with an IIF statement, but I'm having trouble showing both the "Listening Review" and "Target Review" if BothOption is selected. Any thoughts on how I would accomplish this task?

    Thank you,

    Cory

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    radio button ONLY have 1 option. no more.
    otherwise you must use check boxes.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I NEVER use dynamic parameterized query. I prefer VBA to build criteria and set filter for form or report. Review: http://www.allenbrowne.com/ser-62.html

    Are these radio buttons within an Option Group control?

    Post your working expression.
    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.

  4. #4
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    I'm using this IIF statement:

    IIf([Forms]![Summary Page]!
    [ListeningReviewOption]=True,"Listening Review",IIf([Forms]![Summary Page]![TargetReviewOption]=True,"Target Review",IIf([Forms]![Summary Page]![BothOption]=True,"Like "*"")))

    I know it's close but can't get the syntax right for [BothOption]

  5. #5
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    June7, I appreciate your post but I don't think that's going to help in this scenario.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    So these radio buttons are not within an Option Group? They should be to allow only one of the buttons to be selected.

    Problem is the operator (=, Like, etc) cannot be dynamic and cannot be within quotes because then it's just a string, not an operator. So maybe:

    LIKE Switch([Forms]![Summary Page]!
    [ListeningReviewOption] = True, "Listening Review", [Forms]![Summary Page]!
    [ListeningReviewOption] = True, "Target Review", [Forms]![Summary Page]!
    [ListeningReviewOption] = True, "*")
    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
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    I can make it so that they're within an Option Group, but they're not currently like that (I didn't realize that was an option as I am just a beginner with MS Access). Instead, I have VB code written out the long way to ensure this:

    Private Sub ListeningReviewOption_Click()
    If Me.ListeningReviewOption = True Then
    Me.TargetReviewOption = False
    Me.BothOption = False
    Me.Refresh
    End If
    End Sub
    Private Sub TargetReviewOption_Click()
    If Me.TargetReviewOption = True Then
    Me.ListeningReviewOption = False
    Me.BothOption = False
    Me.Refresh
    End If
    End Sub
    Private Sub BothOption_Click()
    If Me.BothOption = True Then
    Me.TargetReviewOption = False
    Me.ListeningReviewOption = False
    Me.Refresh
    End If
    End Sub


    I'll give your suggestion a try. Thank you.

  8. #8
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    June7, you're a genius. Thank you so much for your help!

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

Similar Threads

  1. Replies: 2
    Last Post: 11-03-2015, 08:56 AM
  2. If statement in query - criteria help!
    By fluffyvampirekitten in forum Queries
    Replies: 2
    Last Post: 10-14-2015, 04:09 AM
  3. Replies: 5
    Last Post: 07-02-2014, 07:13 AM
  4. IIf Statement in Query Criteria
    By kyle87 in forum Queries
    Replies: 8
    Last Post: 07-29-2013, 12:31 PM
  5. Replies: 2
    Last Post: 10-19-2012, 01:44 AM

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