Results 1 to 4 of 4
  1. #1
    billybeer is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Posts
    27

    Query to return First word

    I am trying to run a query that will return the first word in a column. I have this; ​Expr1: Left([DFFNAME],InStr([DFFNAME]," ")-1)


    This works when there are multiple words in the column but errors out when there is only one word in the column. What do I need to add to return the first word when there are multiple words and return the one word when there is only one word in the column. This is for a column of first names [DFFNAME] that sometimes has just a first name and sometimes has both first and middle names and I only want the first. Thanks

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Try this:
    Code:
    ​Expr1: IIf(InStr([DFFNAME]," ")>0,Left([DFFNAME],InStr([DFFNAME]," ")-1),[DFFNAME])

  3. #3
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Alternatively, you could also do it like this:
    Code:
    Expr2:Left([DFFNAME] & " ",InStr([DFFNAME] & " "," "))

  4. #4
    billybeer is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Posts
    27
    Works great, thanks for quick response.

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

Similar Threads

  1. Replies: 6
    Last Post: 04-04-2017, 02:50 AM
  2. Replies: 3
    Last Post: 09-15-2016, 08:16 AM
  3. Replies: 12
    Last Post: 10-19-2015, 08:27 PM
  4. Return date from Word to Access
    By lizzywu in forum Import/Export Data
    Replies: 3
    Last Post: 11-23-2011, 01:56 AM
  5. Replies: 1
    Last Post: 12-21-2005, 12:27 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