Results 1 to 12 of 12
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Looking for characters that cause problems

    I made a form late last year that would list records, then loop through and email each record.



    It would check and skip any record with a blank email

    It work without a hitch.

    Then one of the fields had to emails in the field that was separated by a /

    john@email.com / sam@email.com

    When my record source rs! hit that - the whole command stopped there and didn't continue - I now assume the / stops the task.

    fair enough to find the record and delete the / however what should I be looking out for when doing this?

    Should I now make the task check for / in the records before it runs the task?

    Any advice?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Not sure what happened but replace the "/" with a ";" and it should work.

  3. #3
    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,870
    I agree with Allan as long as your logic can handle multiple emails in the field and it's OK to send 1 email to the 2 addresses.
    To me it sounded like you expected only one email in the field.
    You could put in a proc to validate the contents as a valid email address(syntax).

    Jeanette Cunningham has code for email validation at
    http://social.msdn.microsoft.com/For...orum=accessdev

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by orange View Post
    I agree with Allan as long as your logic can handle multiple emails in the field and it's OK to send 1 email to the 2 addresses.
    To me it sounded like you expected only one email in the field.
    You could put in a proc to validate the contents as a valid email address(syntax).

    Jeanette Cunningham has code for email validation at
    http://social.msdn.microsoft.com/For...orum=accessdev
    I know ; works instead of /

    but I guess my question is what else should I be looking for that will break code?

    I know I can ask the form to go through and delete any / character by using replace() to replace any / with ; so that will solve that problem in the future but I worry about things I may not know about yet.

    ps. thanks for the link.

  5. #5
    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,870
    So at this point your code could handle 2 or more email addresses if they are separated by ;.
    ; is the separator when using multiple emails.

    You could find a procedure or regular expression to validate any email address in the field.

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by orange View Post
    So at this point your code could handle 2 or more email addresses if they are separated by ;.
    ; is the separator when using multiple emails.

    You could find a procedure or regular expression to validate any email address in the field.
    The problem I get with validate an email is that you get .com.au or .net.au not just .com

    yeah, Outlook will handle 2 emails if using ; but not / (using the library reference)

  7. #7
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I'm going to have to make a verify email checker thing because some emails have @location. com.au (someone puts a space accidentally) and this too stops the process...



    I am going to use replace to

    remove any / and replace with ""

    remove an " " and replace with ""

  8. #8
    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,870
    I searched for email validate and after seeing how long some of the source vba codes were, I found a regular expression that was
    well rated for most things at http://blog.trojanhunter.com/2012/09...-email-address

    And based on some previous work with reg expressions, I created this function to validate email based on the pattern I found.
    The function takes in a string - the email address to be tested. It returns True if pattern matches; it returns False if it does not.

    You could use this to see if an email has proper format. For your logic if you find multiple emails in one field, you will have to parse
    each email address and test it for valid or not.

    NOTE: You must set a reference to Microsoft VBScript Regular Expressions 5.5

    You could set up the function and test various emails to get some feel for the "completeness" of this pattern.
    I hope it helps.

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : IsValidEmail
    ' Author    : Jack
    ' Date      : 28/01/2014
    ' Purpose   : To create a function to validate an email syntax.
    '
    '                                ---------------------------------------
    '*** Requires a reference to the  Microsoft VBScript Regular Expressions  library
    '                                 _______________________________________
    '
    ' Found "best regex pattern for email validation" at
    '  http://blog.trojanhunter.com/2012/09/26/the-best-regex-to-validate-an-email-address
    '
    ' Pattern is [-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}
    
    'How it works
    ' Function takes in an email address as  string
    ' Using regex pattern matching
    ' If string matches valid email pattern -->return True
    ' If string fails valid email pattern   -->return False
    
    '---------------------------------------------------------------------------------------
    '
    Function IsValidEmail(T As String) As Boolean
    
    10  On Error GoTo IsValidEmail_Error
    
    20  IsValidEmail = False    'preset to False
        Dim re As New Regexp
        'set the pattern
    30  re.Pattern = "[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}"
    40  re.Global = True
    
    
    50  If (re.Test(T) = True) Then
    60      IsValidEmail = True
    70  Else
    80      IsValidEmail = False
    90  End If
    
    100 On Error GoTo 0
    110 Exit Function
    
    IsValidEmail_Error:
    
    120 MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure IsValidEmail of Module Module1"
    
    End Function
    Here is some test output in immediate window

    ?IsValidEmail("jackpat.d@gmail.net.au")
    True
    ?IsValidEmail("jackpat.d?gmail.net.au")
    False
    Last edited by orange; 01-28-2014 at 08:25 PM. Reason: spelling

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by orange View Post
    I searched for email validate and after seeing how long some of the source vba codes were, I found a regular expression that was
    well rated for most things at http://blog.trojanhunter.com/2012/09...-email-address

    And based on some previous work with reg expressions, I created this function to validate email based on the pattern I found.
    The function takes in a string - the email address to be tested. It returns True if pattern matches; it returns False if it does not.

    You could use this to see if an email has proper format. For your logic if you find multiple emails in one field, you will have to parse
    each email address and test it for valid or not.

    NOTE: You must set a reference to Microsoft VBScript Regular Expressions 5.5

    You could set up the function and test various emails to get some feel for the "completeness" of this pattern.
    I hope it helps.

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : IsValidEmail
    ' Author    : Jack
    ' Date      : 28/01/2014
    ' Purpose   : To create a function to validate an email syntax.
    '
    '                                ---------------------------------------
    '*** Requires a reference to the  Microsoft VBScript Regular Expressions  library
    '                                 _______________________________________
    '
    ' Found "best regex pattern for email validation" at
    '  http://blog.trojanhunter.com/2012/09/26/the-best-regex-to-validate-an-email-address
    '
    ' Pattern is [-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}
    
    'How it works
    ' Function takes in an email address as  string
    ' Using regex pattern matching
    ' If string matches valid email pattern -->return True
    ' If string fails valid email pattern   -->return False
    
    '---------------------------------------------------------------------------------------
    '
    Function IsValidEmail(T As String) As Boolean
    
    10  On Error GoTo IsValidEmail_Error
    
    20  IsValidEmail = False    'preset to False
        Dim re As New Regexp
        'set the pattern
    30  re.Pattern = "[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}"
    40  re.Global = True
    
    
    50  If (re.Test(T) = True) Then
    60      IsValidEmail = True
    70  Else
    80      IsValidEmail = False
    90  End If
    
    100 On Error GoTo 0
    110 Exit Function
    
    IsValidEmail_Error:
    
    120 MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure IsValidEmail of Module Module1"
    
    End Function
    Here is some test output in immediate window

    ?IsValidEmail("jackpat.d@gmail.net.au")
    True
    ?IsValidEmail("jackpat.d?gmail.net.au")
    False
    HO-LY **** that looks complicated. I will try it anyway

    I think I get it.

    It checks either side of the @

    checks AZ and 1-9

  10. #10
    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,870

  11. #11
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by orange View Post
    Did you try this function?

    Not yet, it has been added to my huge to do list... mountain. May need rescuing. Send a chopper.

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Send a chopper.
    Sorry... all choppers are grounded due to bad weather.

    Most I can do is send best wishes...

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

Similar Threads

  1. Trim first 13 characters, Cut It Out
    By redbull in forum Programming
    Replies: 2
    Last Post: 09-12-2013, 07:19 AM
  2. (bug) Chinese characters
    By JeroenMioch in forum Access
    Replies: 1
    Last Post: 08-09-2013, 09:15 AM
  3. Replies: 9
    Last Post: 02-11-2013, 03:09 PM
  4. How to count characters?
    By Jorge Junior in forum Access
    Replies: 1
    Last Post: 05-22-2011, 08:07 PM
  5. Special Characters
    By orgelizer in forum Access
    Replies: 0
    Last Post: 03-20-2007, 08: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