Email Criteria

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Email Criteria

Post by burrina »

I'm unsure of my coding as I have not been able to test it yet. Trying to send auto-email to person in tblEmail where techspt = -1
Unsure about .To AND .Body & maybe SendTo

Dim SendTo As String
DimsHost As String
sHostName = Environ$("computername")
SendTo = DLookup(“EmpName”, "tblEmployees", "techspt=-1")

.To = “SendTo”
.Body = "Please check the security settings for, & ([“sHostName”]) & “‘s“ & computer”

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Email Criteria

Post by HansV »

If you use quotes around SendTo and sHostName, VBA will treat them as the literal strings "SendTo" and "sHostName" instead of as variables.
And where you do need quotes, they must be straight quotes, not curly quotes.

Code: Select all

    Dim SendTo As String
    Dim sHostName As String
    sHostName = Environ$("computername")
    SendTo = DLookup("EmpName", "tblEmployees", "techspt=-1")

    .To = SendTo
    .Body = "Please check the security settings for " & sHostName & "'s computer"
P.S. I wouldn't be surprised if an email message with that text ended up in the Spam/Junk folder...
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Email Criteria

Post by burrina »

Thanks, but it is sent to the tech support person in charge of the network. He is aware of the email.
Appreciate the code assist.