Results 1 to 4 of 4
  1. #1
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74

    IIF Statement in Textbox

    Happy Holidays!

    I have a table called TA_Runs with a "Run_ID" field that contain either "Summer" or "Spring". Accordingly, I have created a report which is filtered by either "Spring" or "Summer", and on the report is a text field in the header area that displays the filtered season.



    I would like to code the text box to either show the filtered season (Spring or Summer), or if unfiltered (showing both seasons) to display "All Records"..
    Here is the expression used in the text box on the report form:
    =IIf([RUN_ID]="SUMMER",[RUN_ID],IIf([RUN_ID]="SPRING",[RUN_ID],IIf([RUN_ID]="SUMMER" AND [RUN_ID]="SPRING","ALL RECORDS",[RUN_ID])))

    It works if either SUMMER or SPRING is filtered, but when all records are in view, the box displays either SUMMER or SPRING.
    Again, I'd like the box to display "ALL RECORDS" when report is unfiltered.

    Thanks,

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    I would test what the user entered, presumably on a form, not the data itself. As you're doing it, it's simply looking at the first record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    How do you open the report with filter? How does user select category?

    I would use VBA. Then could use the OpenArgs argument to pass the report category (Summer, Spring, All Records).

    DoCmd.OpenReport "report name", , , , , Me.cbxCategory

    Then textbox on report:

    =[OpenArgs]

    or report textbox can reference form control:

    = [Forms]![formname]![cbxCategory]

    otherwise, have to do some calcs in report header or footer, like:

    =IIf(Sum(IIf(RUN_ID="Summer",1,0))>0 AND Sum(IIf(RUN_ID="Spring",1,0))>0, "ALL RECORDS", IIf(Sum(IIf(RUN_ID="Summer",1,0))>0, "Summer", "Spring"))
    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
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74
    I placed this code in the header and if works fine: =IIf(Sum(IIf(RUN_ID="Summer",1,0))>0 AND Sum(IIf(RUN_ID="Spring",1,0))>0, "ALL RECORDS", IIf(Sum(IIf(RUN_ID="Summer",1,0))>0, "Summer", "Spring"))

    Thanks June7!!

    Happy Holidays.

    -Tommy

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

Similar Threads

  1. Replies: 11
    Last Post: 10-02-2013, 09:59 AM
  2. Replies: 2
    Last Post: 04-20-2013, 03:37 AM
  3. Replies: 3
    Last Post: 01-18-2013, 06:20 PM
  4. Not In statement from textbox - help please
    By jclausen in forum Access
    Replies: 4
    Last Post: 02-03-2011, 05:27 PM
  5. Textbox IIF statement not working
    By jgelpi16 in forum Forms
    Replies: 2
    Last Post: 08-22-2010, 08:41 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