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

    Function that combines email into one string separated by a ;

    I have an email checker that checks for similar emails and merges them into one line for the emails



    function below
    Code:
    'email stored for the TO email field
    Function CombineEmails(strEmail1 As String, strEmail2 As String) As String
    
    
    'if both exist and are the same then combine into one line using ;
    If Not IsNull(strEmail1) And Not IsNull(strEmail2) Then
        If strEmail1 = strEmail2 Then
        CombineEmails = strEmail1
        Else
        CombineEmails = strEmail1 & ";" & strEmail2
        End If
        
    'if the first email exists but the second one is null then email only the first
    ElseIf Not IsNull(strEmail1) And IsNull(strEmail2) Then
        CombineEmails = strEmail1
        
    'if the first doesn't exist and the second one does then email the second
    ElseIf IsNull(strEmail1) And Not IsNull(strEmail2) Then
        CombineEmails = strEmail2
        
    'and if both are blank give message
    ElseIf IsNull(strEmail1) And IsNull(strEmail2) Then
        MsgBox "Note you have no email on this booking, you can still email this however no email will be there to email!"
         CombineEmails = ""
         
    End If
    
    
    End Function
    This works great for the first IF but doesn't work if the second field is blank and I can't work it out.

    if I say

    strEmailPersons = CombineEmails([TeacherEmail],[SchoolEmail])

    it works some of the time not all of the time

  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    ah fixed

    Code:
    'email stored for the TO email field
    Function CombineEmails(strEmail1Pull As Variant, strEmail2Pull As Variant) As String
    
    
    Dim strEmail1 As String
    Dim strEmail2 As String
    strEmail1 = IIf(IsNothing(strEmail1Pull), " ", strEmail1Pull)
    strEmail2 = IIf(IsNothing(strEmail2Pull), " ", strEmail2Pull)
    
    
    
    
    'if both exist and are the same then combine into one line using ;
    If Not IsNull(strEmail1) And Not IsNull(strEmail2) Then
        If strEmail1 = strEmail2 Then
        CombineEmails = strEmail1
        Else
        CombineEmails = strEmail1 & ";" & strEmail2
        End If
        
    'if the first email exists but the second one is null then email only the first
    ElseIf Not IsNull(strEmail1) And IsNull(strEmail2) Then
        CombineEmails = strEmail1
        
    'if the first doesn't exist and the second one does then email the second
    ElseIf IsNull(strEmail1) And Not IsNull(strEmail2) Then
        CombineEmails = strEmail2
        
    'and if both are blank give message
    ElseIf IsNull(strEmail1) And IsNull(strEmail2) Then
        MsgBox "Note you have no email on this booking, you can still email this however no email will be there to email!"
         CombineEmails = ""
         
    End If
    
    
    End Function

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

Similar Threads

  1. Replies: 6
    Last Post: 01-21-2014, 06:39 PM
  2. Replies: 6
    Last Post: 06-07-2013, 09:45 AM
  3. Replies: 2
    Last Post: 04-07-2011, 10:15 AM
  4. Replies: 1
    Last Post: 09-06-2010, 11:45 PM
  5. Replies: 1
    Last Post: 07-31-2009, 03:57 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