Results 1 to 7 of 7
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371

    Removing String And 2 New Lines

    Hi Guy's hope you are all safe and well



    I am trying work out how to remove a string and 2 new lines, so if when I add a new sentence using the Replace function, what is the method of using the replace function to remove the added sentence (paragraph) ?

    The following code works great as it picks out the replaces or adds extra tot he reply

    Code:
    Dim myRow As Integer, NewStr As String, FindStr As String, OrgStr As String, myStr As String, NewReply As String, NewText As String, OldText As String, iOpt As Integer
    
    myRow = Me.cboAddLine.Column(0)
    NewText = Me.cboAddLine.Column(2)
    OldText = Me.cboAddLine.Column(3)
    OrgStr = Forms!frmMainMenu!txtReply
    
    
    Select Case myRow
    Case 1
        myStr = Replace(OrgStr, OldText, NewText & vbNewLine & vbNewLine & OldText)
        Me.txtReply = myStr
    Case 2
        myStr = Replace(OrgStr, OldText, OldText & vbNewLine & vbNewLine & NewText)
        Me.txtReply = myStr
    Case 3
        myStr = Replace(OrgStr, OldText, OldText & vbNewLine & vbNewLine & NewText)
        Me.txtReply = myStr
    Case 4
        myStr = Replace(OrgStr, OldText, OldText & vbNewLine & vbNewLine & NewText)
        Me.txtReply = myStr
    End Select
    The above code is great and works well, just want to have basically an undo button, so now effectively want to undo this back to normal OrgStr (Original text)

    This code I have took some ideas and messed around but I don't think I understand how to use replace to reverse the NewText and remove the x 2 vbNewlines

    A lot of this is bypassed as i am getting lost how to do it

    Code:
    Dim myStr As String, OrgStr As String, NewStr As String
    
    myStr = Me.cboAddLine.Column(2)
    OrgStr = Me.txtReply
    
    
     '   If Len(myStr) <> 0 Then
      '      If Right$(myStr, 2) = vbCrLf Or Right$(myStr, 2) = vbNewLine Then
       '         myStr = Left$(myStr, Len(myStr) - 2)
        '    End If
        'End If
        
        myStr = Replace(OrgStr, myStr, OrgStr)
        Me.txtReply = myStr
        
       ' txt = txt.Replace(vbCr, "").Replace(vbLf, "")
        
        
    'strText = Replace(Replace(strText, Chr(10), ""), Chr(13), "")
    
    
    'If Right(Str, 1) = vbLf Then Str = Left(Str, Len(Str) - 1)
        
    '    myStr = Replace(OrgStr, OldText, NewText & vbNewLine & vbNewLine & OldText)
    'Me.txtReply = myStr
    Please forgive me if i have explained this wrong, we have lost a family member recently so trying get my mind back on track!!!!!!

    Kindest

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,569
    Just save the string to another variable, replace from that when you use Undo?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    we have lost a family member recently
    Condolences to you and your family Dave.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Thank you very kindly, much appreciate your comment moke123

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi welshgasman, that does make sense to save to another variable, string

    The additional change is from combo cboAddLine whereas the undo button is a sperate procedure, please correct me if i am wrong, wouldn't another button have to find the specific text from cboAddline.column(number) then replace with

    Removing text that is equal to cboAddline.Column(number)

    Removing 2 line feeds ?

    Just with it being on a different procedure

    Stand corrected if i am barking up the wrong tree

    Kindest

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Silly me, just add the original reply to a sperate text box hidden, then if i want to undo, tell the original reply to be the sperate hidden box!!!!


    Thanks guy's

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    @DMT Dave; my condolences as well. I don't know what you're feeling but I know the feeling of losing family members over the last year or so.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Removing all spaces in an email string
    By shuddle in forum Forms
    Replies: 8
    Last Post: 02-04-2021, 10:47 AM
  2. Replies: 18
    Last Post: 06-12-2019, 06:29 AM
  3. Removing lines from a query
    By Big D in forum Queries
    Replies: 1
    Last Post: 08-07-2013, 07:54 AM
  4. Replies: 3
    Last Post: 12-28-2011, 01:45 PM
  5. Removing all letters or all numbers from string
    By Hayley_sql in forum Programming
    Replies: 2
    Last Post: 09-16-2009, 02:01 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