Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    St. Charles, Illinois
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Remove carriage returns and extra spaces (Access 2000)

    I have imported data into a memo field. However, there are a tremendous amount of spaces and extra carriage returns. Is there a way to delete more than two spaces and more than two carriage returns. I can export the field to Excel if that would be easier. Maybe use a macro? Thank you.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Remove carriage returns and extra spaces (Access 2000)

    Create a new module and copy the following function into it:

    Function ReplaceChars(s) As Variant
    Dim lngLen As Long
    Dim strOld As String
    Dim strNew As String

    If IsNull(s) Then Exit Function

    strNew = Trim(s)
    Do
    strOld = strNew
    lngLen = Len(strOld)
    strNew = Replace(strOld, Space(2), Space(1))
    Loop Until Len(strNew) = lngLen
    Do
    strOld = strNew
    lngLen = Len(strOld)
    strNew = Replace(strOld, vbCrLf & Space(1), vbCrLf)
    Loop Until Len(strNew) = lngLen
    Do
    strOld = strNew
    lngLen = Len(strOld)
    strNew = Replace(strOld, Space(1) & vbCrLf, vbCrLf)
    Loop Until Len(strNew) = lngLen
    Do
    strOld = strNew
    lngLen = Len(strOld)
    strNew = Replace(strOld, vbCrLf & vbCrLf, vbCrLf)
    Loop Until Len(strNew) = lngLen
    ReplaceChars = Trim(strNew)
    End Function

    You can now create a query based on your table. Either use a calculated field ReplaceChars([MemoFieldName]) or change the query to an update query and set Update to for the memo field to ReplaceChars([MemoFieldName])
    (Of course, you must replace MemoFieldName with the actual name fo the memo field.)

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    St. Charles, Illinois
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove carriage returns and extra spaces (Access 2000)

    Thank you. I really appreciate your assistance. I never could have determined this on my own.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •