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.
??
>>> Form![EmpName]
With something like this:
Forms!YourFormName!EmpName