Fix Email Automation Programming

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
mrl1021Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
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] & ";")
0
infolurkCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
infolurkCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.