Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trimming a field Question. . .

Status
Not open for further replies.

Brambojr

Technical User
Oct 26, 2000
73
US
I have linked my access db to Outlook and certain folders within my Inbox. My question is this . . . At the end of many emails there are many lines of unimportant information that is pretty standard and unchanging. Is there a way through macro or code to chop off this stuff?? Or even just dump it entirely? I would sure appreciate some feed back. I am not too well versed in VBA but am not entirely shy of it either.
 
Assuming you have the entire message in a string variable, if you can identify some sequence of characters that introduce the part you want to chop off, then you can do it. For instance, if you want to chop off everything that begins with the last occurence of the word "Signed", this code will do it:
Code:
    Dim i As Integer, j As Integer
    Dim strMsg As String   ' contains the message text

    i = 1
    Do
        i = Instr(i, strMsg, "Signed")
        If i = 0 Then Exit Do
        j = i
        i = i + Len("Signed")
    Loop
    If j <> 0 Then
        strMsg = Left$(strMsg, j - 1)
    End If
Explanation: The Do loop finds each occurrence, if any of the string &quot;Signed&quot;. Each time it succeeds, the starting position is saved in j. When no more occurrences are found, the loop is exited. This leaves j containing the index of the last occurrence, if one is found; if none were found, j will be 0, its initial value from the Dim statement.

After exiting the loop, we test to see if j <> 0 (that is, if any occurrence was found). If so, we set strMsg to the leftmost part of the message, up to the j-1 position. That chops off the ending. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top