Issue with adding email address to "TO" field in Outlook

mkaeser

Registered User.
Local time
Today, 04:43
Joined
Apr 14, 2014
Messages
74
Hello,

I have vba code set up to automate a query output to email with outlook. I am having issues with the "TO" field. I have tried different types of code, such as the following:

1) MyMail.To = MailList.Fields("EmailAddress")
2) MyMail.To = MailList.Fields("EmailAddress") & ";"

Both of these work, but the issue I am having is the "TO" field in the outlook message looks like this:
admin@blahblah#mailto:admin@blahblah#

For the life of me, I can not find anything help online to figure out why my code is adding the email address twice, I need to get rid of the #mailto:admin@blahblah# but I do not know how or why it keeps adding that end part. Any ideas or suggestions? Thank you!
 
Thank you Spikepl!

So my first update, using the link you posted, is I changed:

MyMail.To = MailList.Fields("EmailAddress")

to

MyMail.To = HyperlinkPart(MailList("EmailAddress"), acAddress)

Results:
mailto:admin@blahblah

So it removed the 2nd address and the "#" but I still have the "mailto" in there, but there is some progress!
 
Ok so here is the solution I have found to remove the duplicate address from the "TO" field in outlook, as well as the "#" and "mailto:":

OutLook = HyperlinkPart(MailList("EmailAddress"), acAddress)
OutLook = Right([OutLook],Len([OutLook])-7)
MyMail.To = OutLook

Thanks for the help, and if anyone has a better way to solve these, please leave the tips!
 

Users who are viewing this thread

Back
Top Bottom