Hyperlink in Email Body (1 Viewer)

Wayne

Crazy Canuck
Local time
Today, 19:17
Joined
Nov 4, 2012
Messages
176
I have created a command button to email each technician the details of their jobs for the next day. It gives the scheduled time, client's name, address, and contact numbers, and the scope of work required, all in the body of the email. Everything is working perfectly, and as they say, if it ain't broke, don't try to fix it.

That being said, one of my techs gave feedback that it would be nice to click on the address or a link in the email body on his phone, and it brings up the corresponding Google map. For some reason, the phone numbers in the email body show up on their phones as hyperlinks, and will dial the number when they click on it, but neither the Android or Apple systems pick up on the address like they do on the phone numbers. I have tried (unsuccessfully) to turn the client's address into a hyperlink, that will show the address on google maps.

The body of the email is in HTML. Here is the code I was using:

Code:
"<a href="https://www.google.ca/maps/place/" & "+" & Me.StreetAddress & _
"+" & Me.CityName & "+" & Me.StateName>View on Map</a>"

It returns an error message "Expected: End of Statement" and highlights the "https:" in the code line as the point it expects that End of Statement. I even tried creating a string for the url, and putting the string name in place of the whole string, but when you click the link on the email, it is trying to find a website called strUrl.

When I use that line of code in VBA (without the HTML coding), it works perfectly, and finds the client's address on Google maps.

I'm kinda stumped here, and would appreciate any help.

Wayne
 

Micron

AWF VIP
Local time
Today, 19:17
Joined
Oct 20, 2018
Messages
3,476
maybe "...Me.StateName & ">View on Map</a>" ?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 16:17
Joined
Oct 29, 2018
Messages
21,358
Hi Wayne. Try using single quotes where you would normally use a double quote in the hyperlink. For example, "<a href='https://...
 

Micron

AWF VIP
Local time
Today, 19:17
Joined
Oct 20, 2018
Messages
3,476
I don't think single quotes inside an html tag will fly. However I think you hit on a second syntax error, so maybe

"<a href=https://www.google.ca/maps/place/+" & Me.StreetAddress & _
"+" & Me.CityName & "+" & Me.StateName & ">View on Map</a>"

or if they are required (I'm forgetting my html) but can't be single then

"<a ""href=https://www.google.ca/maps/place/+" & Me.StreetAddress & _
"+" & Me.CityName & "+" & Me.StateName & "">View on Map</a>"

maybe some help here
http://allenbrowne.com/casu-17.html


 
Last edited:

Micron

AWF VIP
Local time
Today, 19:17
Joined
Oct 20, 2018
Messages
3,476
in order to get a string with this address (ignore " - there to prevent forum from turning it into a compressed link). Dang - doesn't work but code tags work.

Code:
https://www.access-programmers.co.uk/forums/search.php?searchid=13754951
I went as far as 1 variable for one of your control references rather than 3 just to see if I could get that much figured out. This
Code:
Private Sub Command2_Click()
Dim strID As String
Dim strResult As String

strID = "?searchid=13754951"
strResult = "<a href = ""https://www.access-programmers.co.uk/forums/search.php" & strID & """" & ">Testing </a>"
Debug.Print strResult

End Sub
produced this
Code:
<a href = "https://www.access-programmers.co.uk/forums/search.php?searchid=13754951">Testing </a>
Hope that helps.
RATS - I forgot the = as in <a href = (added now)
 
Last edited:

June7

AWF VIP
Local time
Today, 15:17
Joined
Mar 9, 2014
Messages
5,423
I use single quotes within HTML tag:

.HTMLBody = "<html><p style='font-family:verdana;font-size:11pt'>Some message here <a href='url string here'>Click here</a><br><html>" & vbNewLine & .HTMLBody

The GoogleMaps link worked for me. Even with spaces instead of + characters.
 
Last edited:

Wayne

Crazy Canuck
Local time
Today, 19:17
Joined
Nov 4, 2012
Messages
176
Hi Guys,

Thanks for your help. I got it to work with this code:

Code:
"<a href=""https://www.google.ca/maps/place/+" & Me.ClientStreetAddress & "+" & Me.ClientCityName & "+" & Me.ClientState & """" & ">View on Map</a>"

June - it works with either double or single quotes, just not the quotes outside of the <a></a>.

Again, thanks for the guidance - you guys are great.

Wayne
 

June7

AWF VIP
Local time
Today, 15:17
Joined
Mar 9, 2014
Messages
5,423
What I posted is what is in my procedure (except for the generic strings I substituted), using apostrophes. So am not sure what you mean by "not the quotes outside".

So with your code I would do:
Code:
strResult = "<a href='https://www.google.ca/maps/place/+" & Me.ClientStreetAddress & "+" & Me.ClientCityName & "+" & Me.ClientState & "'>View on Map</a>"
 

Wayne

Crazy Canuck
Local time
Today, 19:17
Joined
Nov 4, 2012
Messages
176
June 7:

What I meant by single quotes outside the <a></a> was that in VBA, the HTML code must be surrounded by double quotes like "<a href>"blah, blah, blah"</a>", but it doesn't seem to accept '<a href>"blah, blah, blah"</a>'. As soon as I use the single quotes outside the HTML code markers, VBA thinks it's a comment, and not code.

Thank you for all your help on this one.

Wayne
 

June7

AWF VIP
Local time
Today, 15:17
Joined
Mar 9, 2014
Messages
5,423
That is correct. Except that is not a 'double' quote - it's just a quote mark. A 'single' quote is an apostrophe.

I prefer apostrophes for embedded text delimiters as opposed to doubled quote marks as you used, which I find confusing.
 

Wayne

Crazy Canuck
Local time
Today, 19:17
Joined
Nov 4, 2012
Messages
176
Just my terminology that was confusing. Sorry. But with your help, I got it to work.

Wayne
 

Users who are viewing this thread

Top Bottom