Trying to send email to a DLookup email address

I have a command button on a form which when clicked is supposed to send an email to a DLookup.  Here is the code:

   With objMail
   'Set body format to HTML
     .BodyFormat = olFormatHTML
     .To = DLookup("[ApproverEmail]", "tblEmployees", "[EmpName] = Form![EmpName]")
     '.Cc = ""
     .Subject = "Time Card Approval Notification For Employee - " & [txtEmployeeName] & " - Dated " & [txtTranxDateHeader]
     '.HTMLBody = "<htmltags>Regular Hours = " & [txtTotRegHrs] & "<br>Overtime Hours = " & [txtTotOThrs] & "<br>Total Hours = " & [txtTotTimeCardHrs] & "<br></htmltags>"
     .HTMLBody = "<htmltags>Regular Hours = " & RegHrs & "<br>Overtime Hours = " & OThrs & "<br>Total Hours = " & totHrs & "<br></htmltags>"
   End With

The problem appears to be in the line:

 .To = DLookup("[ApproverEmail]", "tblEmployees", "[EmpName] = Form![EmpName]")

becase if I hard code an email address like:

'.To = ""

it works fine.

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.

Try this:

.To = DLookup("[ApproverEmail]", "tblEmployees", "[EmpName] = " & chr(34) &  Form![EmpName] & chr(34))

Open in new window

assuming EmpName is TEXT.

In the odd chance that it is numeric:

.To = DLookup("[ApproverEmail]", "tblEmployees", "[EmpName] = " &  Form![EmpName] )

Open in new window

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
Also,  depending on where your code is located, you may need to replace this

>>> Form![EmpName]

With something like this:

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.