Results 1 to 5 of 5
  1. #1
    bks designs is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2015
    Posts
    3

    Query "if" expression

    What is wrong with this:



    Hubby: IIf([Husband's Name] Is Not Null,"(" & [Husband's Name] & ")"," ")

    It works in other queries, but will not work in my new query. I have copied and pasted it even. I keep getting a messae when I go to data view: syntax error (comma) in query expression '[2015 2-6yers].IIf([Husband's Name] Is Not Null,"(" & [Husband's Name] & ")"," ").

    This is for a yearbook - an if expression that if there is no husband listed, it is to be blank, but if there is a name it is to be inclosed in parentheses.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Post the entire attempted sql statement.

    Advise not to use spaces and special characters/punctuation (underscore is exception) in naming convention.
    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.

  3. #3
    bks designs is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2015
    Posts
    3
    Hubby: IIf([Husband's Name] Is Not Null,"(" & [Husband's Name] & ")"," ")

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    That's not the entire SQL statement - that is just a single expression to calculate a field within a query. Post the entire query SQL statement as seen in SQL View of query builder. However, since I presume you are using the query builder, that likely won't help with analyzing the issue.

    Really don't see anything wrong with the expression.

    The query works without that expression?

    Consider this alternative expression:

    Hubby: "(" + [Husband's Name] + ")"

    The + is valid concatenation character (holdover from ancient BASIC) but when the field is Null expression will return Null as opposed to & concatenation which will return ().
    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.

  5. #5
    bks designs is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2015
    Posts
    3
    Many thanks for looking at this. This expression has always worked before and was working in one of the queries but not in the other 2. As sometimes happens... I left the computer after working intensely for 5-6 hours, took a break, came back and now the queries are acting properly. I am making note of your suggestion!

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

Similar Threads

  1. Replies: 1
    Last Post: 06-14-2015, 09:48 AM
  2. Replies: 4
    Last Post: 05-22-2015, 02:29 AM
  3. Replies: 2
    Last Post: 03-08-2013, 12:59 PM
  4. Replies: 8
    Last Post: 03-05-2013, 01:20 PM
  5. Replies: 8
    Last Post: 08-05-2011, 02:55 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