Results 1 to 9 of 9
  1. #1
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125

    Expression Builder Blues

    I do not seem to be able to code selective code, for example

    =[FName]& " " & [LName] works beautifully but

    =[Iff sex=”M”,”Mr. & “, “Ms. & “ [FName] & " " & [LName]] gives me an invalid expression syntax error. I've tried all sorts of variations like

    =[Iff sex =”M”,”Mr “, “Ms“] & ". " & [FName] & " " & [LName]] with similar errors.



    I have similar bad results with Choose and Switch functions. Is there a trick involve that I am not aware of? TIA Phil

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    It would help if you had the right function name and parens, etc.

    =[Iff sex=”M”,”Mr. & “, “Ms. & “ [FName] & " " & [LName]]

    SHOULD BE

    =IIf([sex]=”M”,”Mr. “, “Ms. “) & [FName] & " " & [LName]

  3. #3
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    try,
    iif([sex]="M", "Mr." & [FName], "Ms." & [FName])

    EDIT: just noticed that Bob's post beat mine.
    Bob's answer is more correct than mine.
    I was giving an example of the iif() function, his gives a complete answer.

    Dale

  4. #4
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    Gentlemen I used Bob's code and I get a little window asking for the Parameter value of "M". I am stumped! Phil

  5. #5
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    Could there be an Property field that needs addressing besides the control source? TIA Phil

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by justphilip2003 View Post
    Gentlemen I used Bob's code and I get a little window asking for the Parameter value of "M". I am stumped! Phil
    Are you sure that the control or field name is named sex? Do you actually have that field in the form's control source and is it bound to a control on the form?

  7. #7
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    I'm afraid it is. This db is about code and functionally not pretty or meaningful data; I threw in fields that were easy (I thought) to test. The Form ButtonMania has every possible button I could think of and data manipulation, in this case an unbound field using bound fields to populate the unbounded text box. Also, I corrected the code. Small print is difficult for me to see. =Iff([Sex]="M", "Mr. ", "Ms. ") & [FName] & " " & [LName]. Still when I try to save this code, I get a syntax error. TIA Phil

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    As was pointed out earlier, it's IIf not Iff.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by pbaldy View Post
    As was pointed out earlier, it's IIf not Iff.
    ^^^^^^^^^^^^^^ + 1 ^^^^^^^^^^^^^^^^^

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

Similar Threads

  1. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  2. Expression Builder not there
    By schnuber in forum Access
    Replies: 1
    Last Post: 02-17-2012, 01:17 AM
  3. expression builder
    By tonyl in forum Access
    Replies: 3
    Last Post: 11-26-2011, 12:00 AM
  4. Expression Builder or VB ... Help
    By Adynn in forum Access
    Replies: 0
    Last Post: 06-03-2011, 09:51 AM
  5. Expression Builder
    By mistaken_myst in forum Access
    Replies: 2
    Last Post: 05-07-2008, 01:30 PM

Tags for this Thread

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