Add a Google Map button to an Access form

I am trying to add a button my my Access form that takes an address from form fields and brings up a Google map of that address. I have been searching online and only find references that are many years old. Below is what I am trying but it doesn't bring up the address. Only google Maps for my current location.

any help would be greatly appreciated. - Thank You

Dim straddress As String
Dim strlink As String
Dim strstate As String

On Error GoTo myErr
strstate = "New York"

straddress = Forms![selected properties1].address & "+" & Forms![selected properties1].borough & "+" & strstate & "+" & Forms![selected properties1].Zip
strlink = "http://maps.google.com/maps?q=" & straddress
Application.FollowHyperlink strlink

On Error GoTo 0
    Exit Sub

myErr:
    Resume Next
LVL 1
Robert WardlowPresidentAsked:
Who is Participating?
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
hi Robert,

if you are in the code behind the form, you can use Me. instead of Forms![selected properties1]

space between info will be changed to +, but it will still render

'180131 strive4peace
'Google Map
   Dim vAddress As Variant _
      , sDelimiter As String _
      , sURL As String

   vAddress =null

   With Me.address 
      If Not IsNull(.Value) Then
         vAddress = (vAddress + " ") & .Value
      End If
   End With

   With Me.borough 
      If Not IsNull(.Value) Then
         vAddress = (vAddress + " ") & .Value & " NY" 'automatically add NY
      End If
   End With

'   With Me.State
'      If Not IsNull(.Value) Then
'         vAddress = (vAddress + " ") & .Value
'      End If
'   End With
   With Me.Zip
      If Not IsNull(.Value) Then
         vAddress = (vAddress + " ") & .Value
      End If
   End With

   sURL = "https://maps.google.com/maps?q=" & vAddress
   Application.FollowHyperlink sURL

Open in new window

have an awesome day,
crystal
0
 
NorieVBA ExpertCommented:
Robert

I can't really see anything wrong with that code.

What happens if you remove the On Error Resume Next?
0
 
Jeffrey CoachmanMIS LiasonCommented:
Not sure, but I think you are using an old search string

Here is what Google maps seems to be using now:

    https://www.google.com/maps/place/10+David+St,+Holbrook,+NY+11741

This translates to six parameters:
    StreetNumber+StreetName+StreetDesignation+Town+State+Zip

So I create "All six" textboxes and fill them all in (except for the state, ..since that is a variable in your code)
...and this code works fine for me:

Dim straddress As String
Dim strlink As String
Dim strstate As String

strstate = "New York"

    straddress = Me.StreetNumber & "+" & Me.SteetName & "+" & Me.StreetDesignation & "+" & Me.Town & "+" & strstate & "+" & Me.zip
    strlink = "https://www.google.com/maps/place/" & straddress
    Application.FollowHyperlink strlink

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
adding on ... Google will change space to plus, and it is so much easier to specify space!
0
 
Robert WardlowPresidentAuthor Commented:
Thank you Crystal, this is the perfect solution for my problem.
1
 
Robert WardlowPresidentAuthor Commented:
Thank you for your help Jeffrey. I would have had to find a way to separate the Street, Road, Blvd, out of the address.
I appreciate your help
0
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, Robert ~ happy to help
0
 
Robert WardlowPresidentAuthor Commented:
Thank you Norie, I don't think the On Error was my problem. It seems the syntax for Google changed.
0
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
fwiw, I suspect that the problem with your original code was that it might generate 2 or more "+" in a row if something was blank. The syntax did not change... I stumbled on the automatic correction of space to +
0
 
Robert WardlowPresidentAuthor Commented:
Thanks, I was testing with an address where none of the fields were blank and it still didn't work. I guess the auto correction was the key. Thank you
0
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, Robert ~ it is also better to use relative referencing such as Me. -- and use state abbreviation instead of the state name since New York has a space. Also good to test each control.
0
 
Robert WardlowPresidentAuthor Commented:
Thanks,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.