Results 1 to 7 of 7
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Replace Function In A Query

    I have a database that holds a field called PlayaName and in some instances someone input the players number after the name. So sample data would be


    Code:
    Joe Jones
    Bob Bills No# 14
    Halt Halfway No# 32
    My desired output is
    Code:
    Joe Jones
    Bob Bills 
    Halt Halfway
    I tried this syntax, but access gives me an error of the expression you entered has an invalid string.. How should this syntax be written so that if the string contains NO#* then anything after it is stripped?

    Code:
    accuratename: Left(PlayaName, InStr(PlayaName, " (NO# - 1)))

  2. #2
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Okay, after further testing this will work IF the field contains the number, if it does not it throws an error of
    Code:
    #Error
    or
    #Func!
    Code:
    accuratename: Left([PlayaName],InStr([PlayaName],"NO#")-3)

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,528
    Left(PlayaName, InStr(PlayaName, "NO#")-1)

  4. #4
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by ranman256 View Post
    Left(PlayaName, InStr(PlayaName, "NO#")-1)
    That still gives the #Func! if the value does not hold NO#*

  5. #5
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I tried to add in the
    Code:
     iif()
    function but that just completely ignores everything. This syntax is not correct either
    Code:
    iif(PlayaName = "*NO#*", Left([PlayaName],InStr([PlayaName],"NO#")-1), PlayaName)

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Code:
    IIf(InStr([field1],"NO#")>0,Left([field1],InStr([field1],"NO#")-2),[field1]) AS Expr2

  7. #7
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Ah - I did not know you could check >0 with a text string. Thank you for that!

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

Similar Threads

  1. Update query with replace function fails
    By Keven in forum Queries
    Replies: 5
    Last Post: 07-11-2016, 08:59 AM
  2. Replace Function
    By razkowski in forum Queries
    Replies: 7
    Last Post: 10-08-2014, 02:28 PM
  3. Replace Function
    By thescottsman92 in forum Access
    Replies: 5
    Last Post: 09-02-2013, 01:25 AM
  4. Help with Replace Function...
    By redbull in forum Programming
    Replies: 5
    Last Post: 06-27-2013, 04:05 PM
  5. Replies: 3
    Last Post: 06-07-2012, 07:05 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