Results 1 to 12 of 12
  1. #1
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215

    Less/greater than or equal to criteria question.

    The only important fields here are "Period" and "CalcSort".

    I want it so that if on a form someone chooses Feb that the CalcSort field will only show values 1 and 2. I tried putting in the code below, but for some reason I only get back the "CalcSort" value of 0. What am I doing wrong?



    Code:
    IIf([Forms]![Control]="Feb",[CalcSort]>=1 And [CalcSort]<=2,"")
    MainID OE Years Months Dates Net Period CalcSort
    US CO.2015.Baseline US CO 2015 February 2/1/2015 -0.56 Baseline 0
    US CO.2015.Feb US CO 2015 February 2/1/2015 3.24 Feb 2
    US CO.2015.Jan US CO 2015 February 2/1/2015 1.54 Jan 1

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you need the actual form name between control name and forms collective

    IIf([Forms]![MyForm]![Control]="Feb",[CalcSort]>=1 And [CalcSort]<=2,"")

  3. #3
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    IIf([Forms]![Control]="Feb",[CalcSort]>=1 And [CalcSort]<=2,"")
    I think you are missing the value if true part in iif statement.It can show 1 or 2, not both.
    IIF(Condition,IF true this, If false this)
    So, this is a valid statement,
    IIf([Forms]![Control]="Feb",[CalcSort]=2,"")
    If you want to sort the data you can use the date functions to get month number.

  4. #4
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    You are correct about the [MyForm]! part missing. I didn't paste it correctly. However, I still run into the issue of only 0 showing up.

  5. #5
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    Isn't there a way to set the IIF criteria to show multiple values if TRUE?

    For instance:

    Code:
    IF Forms!MyForm!Control = "Feb" Then
          CalcSort <= 2 AND CalcSort >= 1
    End If
    or something like...

    Code:
    IF Forms!MyForm!Control = "Feb" Then
          1 <= CalcSort <=2
    End If
    I want multiple values to show up given that the condition holds true - not just one.

    But for some reason, the way that I wrote it causes only 0 to show up... no idea why.

  6. #6
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Sorry , i misunderstood. What IS supposed to happen if you get 0?

  7. #7
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    I want the values 1 AND 2 to show up given that the criteria is true.

    I always seem to have issues assigning variable values with IIF criteria statements.

    That is, saying IIF(Forms!Form!Control! = "Feb", [CalcSort] <= 2 AND [CalcSort] >= 1, "")

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Is CalcSort a native field in table or a calculated field in query? In other words, are you trying to construct a field named [CalcSort] in query?

    The last posted expression will return True or False or "" - but only if CalcSort is already a field in table or query.

    What exactly do you want to use this expression for - as filter criteria in a query? Or to calculate value for CalcSort?
    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
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    The CalcSort is a calculated field from a table.

    That could be the root of my problem...

    Say that I have:


    Month CalcSort
    February 0
    February 1
    February 2
    February 3
    February 4
    February 5
    February 6
    February 7
    February 8


    And I want the criteria

    IIF ( Forms![MyForm]![Month] = "February", [CalcSort] <= 6 AND [CalcSort] >= 2, "" )

    That is, if the month chosen on a form is February, then display records with CalcSort field values 2,3,4,5,6... otherwise nothing

    But, the TRUE part of the statement seems to never work. even if I just say [CalcSort]>2, it dosen't work. It seems that an if statement can only take as a true value a simple criteria like a word or letter or something and not an expression as I have above.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I don't use calculated fields in table. Presume Access will recognize CalcSort as a number type.

    This is also why I don't use dynamic parameter queries.

    SELECT * FROM tablename WHERE IIf([Forms![MyForm]![Month]="February" AND [CalcSort]>1 AND [CalcSort]<7, True, False)=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.

  11. #11
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    Nailed it. Thank you...

    This actually showed me how to create multiple criteria expressions within an IIF statement.

    Dynamic parameter queries are tricky...

    How do you get around not using them?

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I build filter criteria in VBA and apply to form or report when opened or form Filter property for already open form.

    Review: http://www.allenbrowne.com/ser-62.html
    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.

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

Similar Threads

  1. Replies: 7
    Last Post: 02-09-2015, 12:35 PM
  2. Replies: 13
    Last Post: 01-08-2015, 10:36 AM
  3. Greater than also showing equal to for DATE
    By dcdimon in forum Queries
    Replies: 9
    Last Post: 02-12-2014, 08:03 AM
  4. Replies: 5
    Last Post: 01-09-2014, 03:06 PM
  5. Greater than or equal to date
    By stryder09 in forum Access
    Replies: 1
    Last Post: 04-14-2011, 03:54 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