Results 1 to 6 of 6
  1. #1
    ddeaton66 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    5

    Set a user input as part of expression

    Morning,



    Relative newbie, I am trying to use expression builder to display a text based on a criteria asked for in the query itself. I cannot come up with a way to reference that and identify it; everything else works as advertised. I know "Display Text" I just need to set it based on a user input from the query itself.

    This is where the input comes in criteria: "AMG" Or [Program]

    This is my expression:

    DisplayText: IIf([tbl_unit]![UnitSection]="AMG" And "AMA","xxxxxxxx",IIf([tbl_unit]![UnitSection]="AMG" And "AMP","yyyyyyyyy","zzzzzzzzz"))

    it doesn't pull exactly correctly, but it would be so much easier just to pull the [Program] input

    TIA
    David

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    1. your logic seems to do the same thing twice,so zzzz will never happen.
    2. you cant use AND. that means the value is two things at the same time. you want OR.

    IIf([tbl_unit]![UnitSection]="AMG" or [tbl_unit]![UnitSection] ="AMA","xxxxxxxx","yyyyyyyyy")

    or do you want 3 OPTIONSl:

    IIf([tbl_unit]![UnitSection]="AMG" ,"xxxxxxxx", (iif([tbl_unit]![UnitSection] ="AMA","YYYYY","zzzzzz"))

  3. #3
    ddeaton66 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    5
    I want either xxxx or yyyy but, the input criteria [Program] alone will give me what I want if I can just use that like:

    DisplayText: IIf([Program]="AMA","xxxxxxxx",IIf([Program]"AMP","yyyyyyyyy","zzzzzzzzz"))

    But I do not know how to pull in that user input of [Program]....

    Thanks

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    what do you mean by 'user input'

    If you have a field:

    DisplayText: Iif([Program] = "AMA", "XXX", iif([Program] = "AMP", "YYY", "ZZZ"))

    and there is no field named 'program' in any of the fields in the table you should be prompted to enter the program when the query runs.

    If your PROGRAM is a field on a form you would have to use

    DisplayText: Iif([forms]![FORMNAME]![Program] = "AMA", "XXX", iif([forms]![FORMNAME]![Program] = "AMP", "YYY", "ZZZ"))

  5. #5
    ddeaton66 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    5
    When the query runs, it asks the user for a criteria, [Program], the user will input either AMA or AMP for the request, if I can pull that input into the expression it will output the text I want based on the input. Currently I am trying to use a resultant of the query but it would be much simpler to use the inputted criteria.

    I am relatively new to this, I am sure there is probably a much easier way to do this....

  6. #6
    ddeaton66 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    5
    Got it! Use Eval..... I knew it was simple.

    Thanks to all!

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

Similar Threads

  1. Criteria part in an expression in a query.
    By Perfac in forum Queries
    Replies: 1
    Last Post: 05-18-2016, 11:48 AM
  2. Replies: 1
    Last Post: 11-04-2014, 12:07 PM
  3. Replies: 3
    Last Post: 08-04-2014, 09:52 PM
  4. Replies: 8
    Last Post: 08-03-2014, 09:35 PM
  5. Replies: 0
    Last Post: 01-18-2007, 07:07 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