Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182

    Update Query - Remove carrier returns

    I am trying to write an update query to:


    1. Remove all carrier returns my field
    and
    2. Remove all spaces that occur before "20" in my field. In otherwords, I want " 20" to become "20"

    I tried this: UPDATE Table1 SET Table1.txtDetails = REPLACE([txtDetails], Chr(13) & Chr(10),"");

    I know the above query doesnt account for "removing spaces in front of '20'

    But MS access says it didnt update one field due to a conversion failure.

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    The space in " 20" is not caused by a Carriage return line feed combination.

    Not exactly sure what text you are dealing with, but to remove that space you could try

    UPDATE Table1 SET Table1.txtDetails = REPLACE([txtDetails], " 20","20");

    I'd use a SELECT query to ensure there were not "unwanted" changes.

    see https://www.techonthenet.com/access/...ng/replace.php for details on Replace.

  3. #3
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    Orange,

    1. The data in txtDetails always starts with a space and/or several spaces and/or a carrier return, followed by a 25 digit key. The 25 digit key ALWAYS starts with "20".

    I am aware the <space> next to twenty is not a Carriage Return line. However, I do have carriage returns along with the space."

    For example, I have:

    "


    2017-45-46353y7-246523
    "

    In addition, I may have more than one space. So I may have " 20". Thus, the SQL you posted would not account for multiple spaces.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    How about the TRIM function instead of REPLACE to remove leading and trailing spaces.

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    Replace will remove all identified characters.

    Try this
    Code:
    Sub xspace()
    'chr(10) new line LF
    'chr(13) carriage return
        Dim x As String: x = "a" & "a" & Chr(13) & Chr(10) & "     2017ghjkl   plkjhgfd" & Chr(13) & Chr(10) & "axxx"
       
        x = Replace(x, "a", "")
        Debug.Print "1 " & x
    
        x = Replace(x, Chr(13) & Chr(10), "")
        Debug.Print "2 " & x
    
        x = Replace(x, " ", "")
        Debug.Print "3 " & x
    End Sub
    Results:

    Code:
    1 
         2017ghjkl   plkjhgfd
    xxx
    2      2017ghjkl   plkjhgfdxxx
    3 2017ghjklplkjhgfdxxx

    To do multiple replaces (different criteria)

    Code:
    Sub yspace()
    'chr(10) new line LF
    'chr(13) carriage return
        Dim x As String: x = "a" & "a" & Chr(13) & Chr(10) & "     2017ghjkl   plkjhgfd" & Chr(13) & Chr(10) & "axxx"
        x = Replace(x, "a", "")
        Debug.Print "1 " & x
        x = Replace(Replace(x, "a", ""), Chr(13) & Chr(10), "")
        Debug.Print "2 " & x
        x = Replace(Replace(Replace(x, "a", ""), Chr(13) & Chr(10), ""), " ", "") '<<++++++
        Debug.Print "3 " & x
    End Sub
    Result:

    Code:
    1 
         2017ghjkl   plkjhgfd
    xxx
    2      2017ghjkl   plkjhgfdxxx
    3 2017ghjklplkjhgfdxxx  <=====All criteria used in #3 here

  6. #6
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    Davegri, can I use the trim function to delete everything that comes before the first "20" identified in a string of text?

  7. #7
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    I am a little lost with this Orange. This code would only work if the "20" number was the same. The "20" is the only thing that remains stagnant. It can be 203452348 one day and 203185748 the next.

  8. #8
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    see my updated post #5 to remove the unwanted characters (incrementally, or multicriteria on one line)

    also, is it ????
    chr(10) or
    chr(13) or
    chr(13) & chr(10)

  9. #9
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    Davegri, can I use the trim function to delete everything that comes before the first "20" identified in a string of text?
    As I mentioned, the trim function will remove leading and trailing (only) spaces from a field.
    If you have used REPLACE to replace the CR and LF with spaces, a later trim will remove them.

  10. #10
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    I see. Thank you for the tip Davegri.

    And Orange, the problem is that I need to use a query. Not VBA (at least, I dont know how to use VBA in a query. I only use it in forms to make my life easier)

    My query needs to be an update query that will remove all CR & LF in a specified field across my entire table.

  11. #11
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    Is it only the spaces before the 20? Or all spaces and cr Lf?
    I don't see other spaces in your sample so

    UPDATE Table1 SET Table1.txtDetails = REPLACE(REPLACE([txtDetails], Chr(13) & Chr(10),"")," ","");

    REPLACE([txtDetails], Chr(13) & Chr(10),"") is executed first and removes All Chr(13) & chr(10)

    REPLACE( XXX,," ","") acts on the string after the first replace has been done.

    Test on a sample before modifying important data.

  12. #12
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    I only care about the spaces before "20". I will give this a try tomorrow. Thanks

  13. #13
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    Orange, I tried the code you posted in #11. But I got the following error.



    After I pressed 'yes', no changes were madeClick image for larger version. 

Name:	err.JPG 
Views:	11 
Size:	31.7 KB 
ID:	31893

  14. #14
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    Is there not a way to delete every character that comes before the first "20" in a field?

  15. #15
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    It seems there may be some issues with your Table1.
    Please show us the definition of the table including the design (data types) and some sample records.

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

Similar Threads

  1. Replies: 7
    Last Post: 04-27-2017, 11:00 AM
  2. Query returns nothing
    By jtmott in forum Access
    Replies: 12
    Last Post: 11-04-2015, 09:00 AM
  3. update/remove character from field
    By Ruegen in forum Queries
    Replies: 6
    Last Post: 01-23-2014, 05:08 PM
  4. Cell phone carrier detection
    By crowegreg in forum Programming
    Replies: 4
    Last Post: 03-21-2013, 12:03 PM
  5. Access Update Query returns -1
    By Chris Morag in forum Queries
    Replies: 2
    Last Post: 05-27-2011, 06:02 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