Send email on afterupdate event of a combobox

I'm trying to write code to send an email (preview first) when a combobox has been updated.  I can't get it to work.

I have this code in the afterupdate event of the combobox:

SendEmailOutlook Me.txtEmail, "New Client Alert", "You have been assigned a new client named " & Me.txtFirstName & " " & Me.txtLastName & ".", False, False

Open in new window

And I have this code in a module:

Public Sub SendEmailOutlook(strTo As String, strSubject As String, strBody As String, _
    strFile As String, Optional bFileAttach As Boolean = False, Optional bPreview As Boolean = False)
    On Error GoTo SendEmailOutlookErr
    Dim strEmail As String
    Dim strMsg As String
    Dim oLook As Object
    Dim oMail As Object
    Set oLook = CreateObject("Outlook.Application")
    Set oMail = oLook.createitem(0)
    With oMail
        '.ReplyRecipients.Add ""
        .to = strTo
        '.body = sBody
        .htmlbody = strBody
        .Subject = strSubject
        If strFile <> "" Then
            .Attachments.Add (strFile)
        End If
        If bFileAttach = True Then
            '.Attachments.Add (CurrentProject.Path & "XYZ.XXX")
        End If
        If bPreview = True Then
        End If
    End With
    If bPreview = False Then
        Set oMail = Nothing
        Set oLook = Nothing
    End If
    Exit Sub
        Exit Sub
        MsgBox Err.Description, vbOKOnly, Err.Source & ":" & Err.Number
        Resume SendEmailOutlookErrExit
End Sub

Open in new window

Can someone tell me what I'm doing wrong?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
What happens?

SteveL13Author Commented:
I get this:

Cannot find this file.  Verify the path and file name are correct.

I'm not even send a file. ???
What is in strFile?  What is the point of bFileAttach if you attach a file prior to checking the Boolean?
Rey Obrero (Capricorn1)Commented:
you did not specify if there is a file for attachment or not

try this, copy and paste

SendEmailOutlook Me.txtEmail, "New Client Alert", "You have been assigned a new client named " & Me.txtFirstName & " " & Me.txtLastName & ".","",False, False

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
PS, I would not send the email from the control level event.  I would use the form's AfterUpdate event.  That way you know the change has actually been committed.  If you send it in the control's AfterUpdate event, the record save could still be cancelled and the update won't happen.  To use the Form's AfterUpdate event, you will need a global variable or preferably a TempVar.  Set the TempVar to False in the Form's Current event.  In the control's AfterUpdate event, set the TempVar to True.  In the Form's AfterUpdate event, check the TempVar and send the email if necessary.  Then reset the TempVar to False.
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.