Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    staceyo is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    7

    IIF statements?

    Hi,
    I have biological data in a query and need a column which has brings all the data together. But not all the cells have information in them.

    So I would like one column (called Taxa) which combines all the data together.
    So far I have tried using an IIF statement, but where some of the data is null, I get an extra space, and can't work out how best to combine these columns into one.

    This is the IIF statement I have so far:

    Taxa: IIf([SUBGENUS] Is Not Null,[GENUS] & " " & "(" & [SUBGENUS] & ")" & " " & [SPECIES] & " " & [AUTHORITY],[GENUS] & " " & [SPECIES] & " " & [AUTHORITY])

    Oh, and should subgenus be present, it needs to have brackets around it...!
    Any help would be very much appreciated!
    Thanks!
    Last edited by staceyo; 09-22-2010 at 06:57 PM. Reason: my table didnt work!

  2. #2
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by staceyo View Post
    Hi,
    I have biological data in a query and need a column which has brings all the data together. But not all the cells have information in them.

    So I would like one column (called Taxa) which combines all the data together.
    So far I have tried using an IIF statement, but where some of the data is null, I get an extra space, and can't work out how best to combine these columns into one.

    This is the IIF statement I have so far:

    Taxa: IIf([SUBGENUS] Is Not Null,[GENUS] & " " & "(" & [SUBGENUS] & ")" & " " & [SPECIES] & " " & [AUTHORITY],[GENUS] & " " & [SPECIES] & " " & [AUTHORITY])

    Oh, and should subgenus be present, it needs to have brackets around it...!
    Any help would be very much appreciated!
    Thanks!

    If you want brackets try this:
    Code:
    Taxa: [GENUS] & IIf(IsNull([SUBGENUS], " " , " [" &  [SUBGENUS] & "]  ") & [SPECIES] & " " &  [AUTHORITY],
    If you want Parentheses try this:
    Code:
    Taxa: [GENUS] & IIf(IsNull([SUBGENUS], " " , " (" &  [SUBGENUS] & ")  ") & [SPECIES] & " " &  [AUTHORITY],

  3. #3
    staceyo is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    7
    Thanks HiTechCoach,

    I tried that with various variations, but keeps telling me I have an invalid syntax! And I'm not even sure what that means, so I'm not doing well to solve the problem.

    As not all the columns are always used (subgenus/subspecies0, I guess to avoid extra spaces, the query should be something along the lines of:

    Taxa: [GENUS]&" "&IIF(IsNull [SUBGENUS] ," ","("[SUBGENUS] ")") & [SPECIES] &" "& IIF(IsNull [SUBSPECIES] ," ", [SUBSPECIES]) &" "& [AUTHORITY]

    Correct?
    Except for the invalid syntax it keeps telling me I have...

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Staceyo:
    remove the space in " " in you original query, then it will work.

  5. #5
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by staceyo View Post
    Thanks HiTechCoach,

    I tried that with various variations, but keeps telling me I have an invalid syntax! And I'm not even sure what that means, so I'm not doing well to solve the problem.

    As not all the columns are always used (subgenus/subspecies0, I guess to avoid extra spaces, the query should be something along the lines of:

    Taxa: [GENUS]&" "&IIF(IsNull [SUBGENUS] ," ","("[SUBGENUS] ")") & [SPECIES] &" "& IIF(IsNull [SUBSPECIES] ," ", [SUBSPECIES]) &" "& [AUTHORITY]

    Correct?
    Except for the invalid syntax it keeps telling me I have...
    Try:

    Taxa: [GENUS]&" "&IIF(IsNull [SUBGENUS] ," ","(" & [SUBGENUS] & ")") & [SPECIES] &" "& IIF(IsNull [SUBSPECIES] ," ", [SUBSPECIES]) &" "& [AUTHORITY]

    Boyd Trimmell aka Hitechcoach
    Microsoft Access MVP
    Started with Access 2.0. Now using the latest version of Access.
    Last edited by HiTechCoach; 09-28-2010 at 01:26 PM.

  6. #6
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by weekend00 View Post
    Staceyo:
    remove the space in " " in you original query, then it will work.
    Which one?

    Boyd Trimmell aka Hitechcoach
    Microsoft Access MVP
    Started with Access 2.0. Now using the latest version of Access.
    Last edited by HiTechCoach; 09-28-2010 at 01:27 PM.

  7. #7
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Quote Originally Posted by HiTechCoach View Post
    Which one?
    Taxa: IIf([SUBGENUS] Is Not Null,[GENUS] & " " & "(" & [SUBGENUS] & ")" & " " & [SPECIES] & " " & [AUTHORITY],[GENUS] & " " & [SPECIES] & " " & [AUTHORITY])

  8. #8
    staceyo is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    7
    Weekend00 - that query does work, except if I have something in the subgenus/subspecies column, it gets missed as that query only works if both are filled in, not if only one is filled in.

    HiTechCoach - I tried the query you suggested, and still says I have invalid syntax...?

    I will keep trying...!

  9. #9
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Will you post the current SQL you are using?

    Boyd Trimmell aka Hitechcoach
    Microsoft Access MVP
    Started with Access 2.0. Now using the latest version of Access.
    Last edited by HiTechCoach; 09-28-2010 at 01:27 PM.

  10. #10
    staceyo is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    7
    I am not an administrator for the database, so cant figure out how to get the SQL info, but using SQL Server 2000, I believe, if that is any help?

    Also, a co-worker has suggested I paste the SQL view of the query I am working on as it may help?

    SELECT Crustacea_InWS4_Yes.CLASS, Crustacea_InWS4_Yes.ORDER, Crustacea_InWS4_Yes.SUBORDER, Crustacea_InWS4_Yes.INFRAORDER, Crustacea_InWS4_Yes.FAMILY, IIf([Crustacea_InWS4_Yes]![SUBGENUS] And [Crustacea_InWS4_Yes]![SUBSPECIES] Is Not Null,[Crustacea_InWS4_Yes]![GENUS] & " " & "(" & [Crustacea_InWS4_Yes]![SUBGENUS] & ")" & " " & [Crustacea_InWS4_Yes]![SPECIES] & " " & [Crustacea_InWS4_Yes]![SUBSPECIES] & " " & [Crustacea_InWS4_Yes]![AUTHORITY],[Crustacea_InWS4_Yes]![GENUS] & " " & [Crustacea_InWS4_Yes]![SPECIES] & " " & [Crustacea_InWS4_Yes]![AUTHORITY]) AS Taxa, Crustacea_InWS4_Yes.NEAREST, Count(Crustacea_InWS4_Yes.DB_ID) AS CountOfDB_ID
    FROM Crustacea_InWS4_Yes
    GROUP BY Crustacea_InWS4_Yes.CLASS, Crustacea_InWS4_Yes.ORDER, Crustacea_InWS4_Yes.SUBORDER, Crustacea_InWS4_Yes.INFRAORDER, Crustacea_InWS4_Yes.FAMILY, IIf([Crustacea_InWS4_Yes]![SUBGENUS] And [Crustacea_InWS4_Yes]![SUBSPECIES] Is Not Null,[Crustacea_InWS4_Yes]![GENUS] & " " & "(" & [Crustacea_InWS4_Yes]![SUBGENUS] & ")" & " " & [Crustacea_InWS4_Yes]![SPECIES] & " " & [Crustacea_InWS4_Yes]![SUBSPECIES] & " " & [Crustacea_InWS4_Yes]![AUTHORITY],[Crustacea_InWS4_Yes]![GENUS] & " " & [Crustacea_InWS4_Yes]![SPECIES] & " " & [Crustacea_InWS4_Yes]![AUTHORITY]), Crustacea_InWS4_Yes.NEAREST
    ORDER BY Crustacea_InWS4_Yes.CLASS, Crustacea_InWS4_Yes.ORDER, Crustacea_InWS4_Yes.SUBORDER, Crustacea_InWS4_Yes.INFRAORDER, Crustacea_InWS4_Yes.FAMILY, IIf([Crustacea_InWS4_Yes]![SUBGENUS] And [Crustacea_InWS4_Yes]![SUBSPECIES] Is Not Null,[Crustacea_InWS4_Yes]![GENUS] & " " & "(" & [Crustacea_InWS4_Yes]![SUBGENUS] & ")" & " " & [Crustacea_InWS4_Yes]![SPECIES] & " " & [Crustacea_InWS4_Yes]![SUBSPECIES] & " " & [Crustacea_InWS4_Yes]![AUTHORITY],[Crustacea_InWS4_Yes]![GENUS] & " " & [Crustacea_InWS4_Yes]![SPECIES] & " " & [Crustacea_InWS4_Yes]![AUTHORITY]);

    It is that last bit that I am having trouble with.

  11. #11
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Try this:

    Code:
     [Crustacea_InWS4_Yes]![GENUS] & " " & "("+[Crustacea_InWS4_Yes]![SUBGENUS]+") " & [Crustacea_InWS4_Yes]![SPECIES] & " " & [Crustacea_InWS4_Yes]![SUBSPECIES]+" " & [Crustacea_InWS4_Yes]![AUTHORITY] AS Taxa
    I have attached my test database

    Boyd Trimmell aka Hitechcoach
    Microsoft Access MVP
    Started with Access 2.0. Now using the latest version of Access.
    Last edited by HiTechCoach; 09-28-2010 at 01:27 PM.

  12. #12
    staceyo is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    7
    Thanks so much HiTechCoach!
    I don't understand how, but that seems to be doing the trick!!!

    Just one more thing, if the authority column is also blank, how would I ammend the query so that it doesn't end up with a space at the end?

  13. #13
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Try changing the last & to a + like this:

    [Crustacea_InWS4_Yes]![GENUS] & " " & "("+[Crustacea_InWS4_Yes]![SUBGENUS]+") " & [Crustacea_InWS4_Yes]![SPECIES] & " " & [Crustacea_InWS4_Yes]![SUBSPECIES]+" " + [Crustacea_InWS4_Yes]![AUTHORITY] AS Taxa

    or use Trim() this:

    Trim([Crustacea_InWS4_Yes]![GENUS] & " " & "("+[Crustacea_InWS4_Yes]![SUBGENUS]+") " & [Crustacea_InWS4_Yes]![SPECIES] & " " & [Crustacea_InWS4_Yes]![SUBSPECIES]+" " & [Crustacea_InWS4_Yes]![AUTHORITY]) AS Taxa

    Boyd Trimmell aka Hitechcoach
    Microsoft Access MVP
    Started with Access 2.0. Now using the latest version of Access.
    Last edited by HiTechCoach; 09-28-2010 at 01:27 PM.

  14. #14
    staceyo is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    7
    Hey HiTechCoach,

    Don't worry, our Admin guy (who works at another company) dropped by today, so he's ammended the query to take out the extra space at the end if the Authority column is blank by using Trim around the whole query.

    Thanks for all your help!

  15. #15
    staceyo is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    7
    sorry, I hadn't refreshed my page, so didn't see your new post!
    Cheers!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. If statements criteria
    By BED in forum Forms
    Replies: 4
    Last Post: 07-23-2010, 12:52 PM
  2. SQL statements from VBA
    By John Southern in forum Programming
    Replies: 12
    Last Post: 05-16-2010, 01:07 PM
  3. Query for IIF statements
    By SpotoR1 in forum Queries
    Replies: 2
    Last Post: 08-26-2009, 06:57 AM
  4. IIF Statements
    By JDA2005 in forum Queries
    Replies: 8
    Last Post: 07-07-2009, 04:24 PM
  5. If statements
    By Ezeecopy in forum Access
    Replies: 0
    Last Post: 03-24-2009, 04:54 AM

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