We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Fix Email Automation Programming

mrl1021
mrl1021 asked
on
Medium Priority
343 Views
Last Modified: 2012-06-21
Please translate the code below. I need to make changes in it. The code is pulling email adresses from two columns: FHEmail and HomeEmail. The FHEmail data was stored as lastname, firstname but we have changed it to the traditional ____@___.___  I need to change the code so it can place these emails in the to box of Outlook like it does the HomeEmail which is in that format already.

Private Sub Command60_Click()
Dim rs As DAO.Recordset, FirstLastName As String, CommaLocation As Long

Dim SendToAddresses As String

Set rs = CurrentDb.OpenRecordset("CH Query")  'create an internal set of the record of your table

Do Until rs.EOF     'do this until the End Of File
    If Nz(rs![FHEmail], "") <> "" Then
        'Find comma, remove it, reverse first and last names:
        CommaLocation = InStr(rs![FHEmail], ",")
        FirstLastName = Mid(rs![FHEmail], CommaLocation + 2) & " " & Left(rs![FHEmail], CommaLocation - 1) & ";"
    Else
        FirstLastName = ""
    End If
    SendToAddresses = SendToAddresses & FirstLastName & IIf(Nz(rs![HomeEmail], "") = "", "", rs![HomeEmail] & ";")
    rs.MoveNext       'Move to the next record
Loop
SendToAddresses = Left(SendToAddresses, Len(SendToAddresses) - 1) 'remove last semicolon

'This line will allow you edit the message with all the emails in the to box
DoCmd.SendObject , , , SendToAddresses

End Sub
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
Try this modification... Just adding  FHEmail to the SendToAddress string:

    SendToAddresses = SendToAddresses & FirstLastName & IIf(Nz(rs![HomeEmail], "") = "", "", rs![HomeEmail] & ";") & IIf(Nz(rs![FHEmail], "") = "", "", rs![FHEmail] & ";")
Commented:
Try

Private Sub Command60_Click()
Dim rs As DAO.Recordset
Dim SendToAddresses As String

Set rs = CurrentDb.OpenRecordset("CH Query")  'create an internal set of the record of your table

Do Until rs.EOF     'do this until the End Of File
    SendToAddresses = SendToAddresses & IIf(Nz(rs![FHEmail], "") = "", "", rs![FHEmail] & ";") & IIf(Nz(rs![HomeEmail], "") = "", "", rs![HomeEmail] & ";")
    rs.MoveNext       'Move to the next record
Loop
SendToAddresses = Left(SendToAddresses, Len(SendToAddresses) - 1) 'remove last semicolon

'This line will allow you edit the message with all the emails in the to box
DoCmd.SendObject , , , SendToAddresses

End Sub

If  FHEmail is in the same format as HomeEmail it should work.

Cheers
Steve

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
You can delete the string manupulation code as you shouldnt need it any more.
I.E this part
If Nz(rs![FHEmail], "") <> "" Then
        'Find comma, remove it, reverse first and last names:
        CommaLocation = InStr(rs![FHEmail], ",")
        FirstLastName = Mid(rs![FHEmail], CommaLocation + 2) & " " & Left(rs![FHEmail], CommaLocation - 1) & ";"
    Else
        FirstLastName = ""
    End If
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.