Results 1 to 4 of 4
  1. #1
    jwhitley is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    1

    Removing text between parentheses.

    I’m using Access 2010 and need a VBA solution to remove text between parentheses on a memo field. The text form the save filed looks like this,



    Notes
    (Username and timestamp)
    Some more notes.
    (A different Username and a different timestamp)
    Even more notes.

    I need to send this to another field for exporting a report without the usernames and timestamps.

    Notes
    Some more notes.
    Even more notes.

    Thanks in advanced!

  2. #2
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Is the example above the exact text that will be in the ()??? if so, I can help with a regex statement.. if it is not, then post an example please.

  3. #3
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    here is an example of what I am talking about. You see with this statement, we are able to locate the text between ( and ) and replace it with "". We can put regex statements in the code - Here is the regex statement, \((?<=\().*?(?=\))\)

    http://regexr.com?33emq

    Click on the replace tab

  4. #4
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    This code opens a txt file, runs the regex against it.. then saves the output as a different file...

    Code:
    Sub RegEx()
    
    
      Dim oFS As FileSystemObject
      Dim oText As TextStream
      Dim strRawData, strFormattedData As String
      Dim oRegEx As RegExp
      Dim oMatches As MatchCollection
      Dim oMatch As Match
    
    
      Set oRegEx = New RegExp
      oRegEx.Global = True
      oRegEx.Pattern = "\s[A-Z0-9\s]*\s*\d{7,12}\s*[^(]\d\d:\d\d[^)]\s*\d*/\d*/\d*\s"
      ' Other ID    \s[A-Z0-9]\s*
      ' Invoice #   \d{10,}\s*
      ' Time        [^(]\d\d:\d\d[^)]
      ' Date        \s\d*/\d*/\d*\s
        
      Set oFS = New FileSystemObject
      Set oText = oFS.OpenTextFile("Sourcefile.txt", ForReading)
        
      strRawData = oText.ReadAll
        
      oText.Close
      Set oText = Nothing
      
      Set oMatches = oRegEx.Execute(strRawData)
    
    
      Set oText = oFS.OpenTextFile("outputfile" & Format(Date, "mm-dd-yyyy") & ".txt", ForWriting, True)
      
      For Each oMatch In oMatches
        strFormattedData = Replace(oMatch, vbCr, "")
        oText.WriteLine Replace(strFormattedData, vbLf, "")
      Next oMatch
      
      oText.Close
      Set oText = Nothing
      
      Set oRegEx = Nothing
      Set oMatches = Nothing
      
      Set oFS = Nothing
    
    
      MsgBox "New Parsed File Created"
    End Sub

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

Similar Threads

  1. Replies: 1
    Last Post: 10-29-2012, 03:07 PM
  2. Removing duplicates
    By DAVID W in forum Access
    Replies: 5
    Last Post: 12-21-2011, 03:15 PM
  3. Replies: 7
    Last Post: 08-28-2011, 02:07 PM
  4. Need help removing duplicates
    By warlock in forum Queries
    Replies: 1
    Last Post: 04-14-2011, 03:44 PM
  5. Removing parameters
    By katrinanyc926 in forum Reports
    Replies: 1
    Last Post: 08-04-2010, 04:24 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