Results 1 to 6 of 6
  1. #1
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    43

    Remove multiple occurrences of text from a string

    I have a linked table from an accounting program that has data in a single field like below:



    [Location]
    BLDG:1-2
    BLDG:1-5, BLDG:1-16
    BLDG:1-2
    BLDG:1-2, BLDG:1-5, BLDG:1-119

    I want my select query to remove all of the BLDG: so it looks like this:

    1-2
    1-5, 1-16
    1-2
    1-2, 1-5, 1-19

    Can this be done within my select query?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    did you try replace([location], "BLDG:", "")

  3. #3
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    43
    Just tried it, and for some reason it does not remove them. it does give "error" on null fields, which I can work around.

  4. #4
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    43
    strange, it didn't like the : in there, i removed it from the replace string, and it then worked, put it back in, and it continued to work.

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    it worked for me to handle nulls you'd just do


    iif(isnull([location]), null, replace([location], "BLDG:", "")

    assuming you're trying to do this in a query.


    note this will not work if you have a space between your BLDG and your colon the text string has to match exactly what you're trying to remove.

  6. #6
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    43
    wound up using

    location: IIf(Nz([Qty_On_Hand].[location],"")="","",Replace([Qty_On_Hand].[location],"BLDG:",""))

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

Similar Threads

  1. Text String from Form Query - Multiple Choices
    By wrandyrice in forum Access
    Replies: 1
    Last Post: 08-12-2012, 10:58 AM
  2. Replies: 3
    Last Post: 05-29-2012, 04:47 PM
  3. Replies: 5
    Last Post: 03-10-2011, 02:19 PM
  4. Remove zeros within a number string
    By catguy in forum Queries
    Replies: 3
    Last Post: 02-25-2010, 07:47 AM
  5. I need to remove a dash from a number string.
    By catguy in forum Programming
    Replies: 3
    Last Post: 02-18-2010, 02:56 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