Results 1 to 6 of 6
  1. #1
    Carol Geddes is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    3

    Parameters in a query?

    I have placed an expression column to concatenate the whole names of clients.



    I used an IIF as the expression. I originally used " " to make a space and " and " to of course make the word and with a space on each side of it.

    WholeNames: IIf([FName2] Is Not Null,IIf([ComLaw]=True,[FName1] & [ ] & [LName1] & [ ] & [“and”] & [FName2] & [ ] & [LName2],[FName1] & [“and”] & [FName2] & [ ] & [LName1]),[FName1] & [ ] & [LName1])

    When I run the query I get a parameter dialog box asking me to enter the parameter value. It makes no difference if I have "" in there with no square brackets or whether I have it placed in the square brackets.
    I realize that normally these kind of IIF's are better placed in a report or in word when the names are merged.
    I would really like to use the expression field in Word rather than placing the code there.

    Why does my query not recognise my & " " & ?
    Thanks
    Carol

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    In IIf, don't use Is Not Null - use Not IsNull([FName2]). Don't use [ ] to define literal text (or space) - use " ".

    WholeNames: IIf(Not IsNull([FName2]), IIf([ComLaw]=True, [FName1] & " " & [LName1] & " and " & [FName2] & " " & [LName2], [FName1] & " and " & [FName2] & " " & [LName1]), [FName1] & " " & [LName1])
    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
    Carol Geddes is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    3
    Thank you for the Not IsNull
    I will try that.

    I have now replaced the [] with & " " & throughout my other expression column named WholeStreet.

    WholeStreet: IIf([Unit#]=Null,[House#] & “ “ & [Street] & “ “ & [StType] & “ “ & [Quad],[Unit#] & “ “ & [House#] & “ “& [Street] & “ “ & [StType] & “ “ & [Quad])

    Now when I run this query it says that I have Invalid Syntax.

    It at least ran with the [] in there. Now it won't run at all.

    ??

    Sorry that I have such a poor understanding of this.
    Carol

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Can't use =Null, nothing is ever =Null. Review (see Error 5): http://allenbrowne.com/casu-12.html

    That IIf syntax has an error but this is simpler:

    WholeStreet: [Unit#] & IIf(IsNull([Unit#]), "", " ") & [House#] & " " & [Street] & " " & [StType] & " " [Quad]


    BTW, advise no special characters or punctuation (underscore is exception) in names.
    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
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    By the way, if you're using IIF, and you're testing for Not IsNull(x), just use IsNull(x) and swap the order of the other two parameters. Easier to read.

  6. #6
    Carol Geddes is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    3
    Thank you all.
    I see the error of my ways
    Carol

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

Similar Threads

  1. Problem about parameters in query
    By ryantam626 in forum Programming
    Replies: 5
    Last Post: 08-22-2012, 08:06 PM
  2. query help with parameters
    By Madmax in forum Access
    Replies: 2
    Last Post: 03-05-2012, 03:07 PM
  3. Passing parameters to a query
    By stephenaa5 in forum Queries
    Replies: 3
    Last Post: 09-10-2010, 05:32 PM
  4. Msgbox in a query with parameters
    By seb in forum Forms
    Replies: 7
    Last Post: 07-06-2010, 05:07 AM
  5. Replies: 3
    Last Post: 07-01-2010, 07: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