troubleshooting Question

Trying to send email to a DLookup email address

Avatar of SteveL13
SteveL13Flag for United States of America asked on
Microsoft Access
2 Comments1 Solution851 ViewsLast Modified:
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.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros