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

    Replace Or Trim Email Address

    Hi Guy's what is the best method to trim or replace and email address ?

    So if i have an incoming email, I may have the following in a text box

    To: dave@home.com <dave@home.com>

    How do I take out everything between <> so I get dave@home.com ?



    Many Thanks

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    I think this topic was just covered within the last couple of days. I didn't participate so it would be hard for me to find. You could try or maybe a participant will provide a link.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Hi Dave,

    Here's a sample function. And test routine.
    Code:
    Function ShortEmail(email As String) As String
      
        Dim LB As Integer, RB As Integer 'LB Left Brace RB  Right Brace
        LB = InStr(email, "<")
        RB = InStr(email, ">")
        'Debug.Print "email original: " & email
        If RB > 0 And LB > 0 Then
            email = Trim(Mid(email, 1, LB - 1))
            'Debug.Print "email revised: " & email
        End If
        ShortEmail = email
    End Function
    Code:
    Sub testshortemail()
    
        Dim mail(2) As String, i As Integer
        mail(0) = "dave@home.com <dave@home.com> "
        mail(1) = "sombodycalled.bob@gmail.com"
        mail(2) = "    imaGambler@genie.net <ig@genie.net>"
    
        For i = 0 To 2
            Debug.Print ShortEmail(mail(i))
        Next i
    End Sub
    which gives:


  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,553
    Just look for the separating characters(s) and use the rest.
    Instr() will help find that character, Left() will get your required string.
    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

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Thank you guy's just couldn't think of the method, weather it was Instr, Trim, Replace or which way to go about it but thank you for your answers, I think with the recent loss of family member, I can't see the wood for the trees!, i should make a short list of what i'm doing then at a later date when the mind set is right, ask then but i just can't stop wanting to learn

    Will test it out

    Thanks again

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

Similar Threads

  1. Replies: 12
    Last Post: 04-06-2018, 01:46 PM
  2. Replies: 2
    Last Post: 05-04-2017, 08:06 AM
  3. Replies: 1
    Last Post: 11-07-2016, 11:18 AM
  4. Email report to value (email address) in a field
    By JackieEVSC in forum Programming
    Replies: 7
    Last Post: 08-28-2015, 11:18 AM
  5. Replies: 1
    Last Post: 05-01-2014, 11:37 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