Results 1 to 6 of 6
  1. #1
    bvallez is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    3

    Remove lines from Memo field

    I have a memo field that contains lines of text. Each line ends with a carriage return/line feed.



    I want to "remove" (or replace with blank space) lines that start with specific text.

    Data in memo field:
    UPS 1Z1234
    UPS 1Z23456
    Shipping Charges $25.50
    UPS 1Z4567
    UPS 1Z8910
    Shipping Charges $23.80

    I would like to end up with:
    UPS 1Z1234
    UPS 1Z23456
    UPS 1Z4567
    UPS 1Z8910

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    try searching for "vbcr" or "vbcrlf" in the find/replace dialog when in datasheet view of the table. If I remember right, I did that once and it works.

  3. #3
    bvallez is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    3
    I should have been more clear. In my example, I want to remove lines that start with "Shipping Charges"...but retain all others.

    See my examples of what data is in the field, and where I want to end up.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Just out of curiosity, why not create a table and store individual records that can be linked to your main table (whatever that is) in a 1 to many relationship.

    Structuring a memo field, as you are finding out, is not a long term solution.

    Just my $.02

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
    Dim db As Database
    Dim rst As Recordset
    Dim sSQL As String
    Dim sMemo As String
    Dim sParsedData As Variant
    Dim i As Integer
    Dim sMemoConv As String
    
    
    Set db = CurrentDb
    
    sSQL = "SELECT * FROM tbl_Memos"
    Set rst = db.OpenRecordset(sSQL)
    
    rst.MoveFirst
    
    Do While rst.EOF <> True
        sMemo = rst.Fields("memofield")
        sParsedData = Split(sMemo, vbCrLf)
        sMemoConv = ""
        For i = 0 To UBound(sParsedData)
            sline = sParsedData(i)
            If Left(sline, 4) <> "Ship" Then
                sMemoConv = sMemoConv & sline & vbCrLf
            End If
        Next i
        rst.Edit
        rst.Fields("MemoField").Value = sMemoConv
        rst.Update
        Debug.Print sMemoConv
        rst.MoveNext
    Loop
    rst.Close
    Set db = Nothing
    this will parse your memo fields and remove any line that starts with "SHIP", you'll have to insert your own table and field names though. Just one word of warning. I am running an update on the same field I'm processing which is a dangerous practice but it's just an example. You will likely want to perform the update on a separate field to make sure yours works before implementing it.

  6. #6
    bvallez is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    3
    rpeare, thank you for this code! Accomplished exactly what I needed!

    Thanks.

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

Similar Threads

  1. Memo Field
    By joekuhn in forum Access
    Replies: 2
    Last Post: 07-10-2011, 09:00 PM
  2. Memo Field
    By maintt in forum Forms
    Replies: 3
    Last Post: 08-24-2010, 07:39 AM
  3. Memo field ?
    By beast_b9 in forum Access
    Replies: 2
    Last Post: 05-26-2010, 08:09 AM
  4. Remove contents from each field
    By nancyszn in forum Access
    Replies: 7
    Last Post: 08-06-2009, 03:41 PM
  5. MEMO field
    By casporov in forum Access
    Replies: 1
    Last Post: 11-11-2006, 08:17 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