Avatar of SteveL13
SteveL13Flag for United States of America

asked on 

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 = "ccaddress@yourmailaddress.com"
     .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>"
     .send
   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 = "name@somecompany.com"

it works fine.

??
Microsoft Access

Avatar of undefined
Last Comment
mbizup
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Also,  depending on where your code is located, you may need to replace this

>>> Form![EmpName]

With something like this:


Forms!YourFormName!EmpName
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo