The On Click event for the button on your Form should call a procedure like this. You would get the sAddr value from the current address shown on your form.
Code:
'---------------------------------------------------------------------------------------
' Procedure : StreetToGoogleMap
' Author : Jack (using Acc2003)
' Created : 7/13/2011
' Purpose : To output a google map based on a street address
' consisting of
' Street, City/Town, State/Prov, Country
'---------------------------------------------------------------------------------------
' Last Modified:
'
' Inputs: sAddr ( a string representing an address)
' Dependency: N/A
'------------------------------------------------------------------------------
'
Sub StreetToGoogleMap(sAddr As String)
'
'NOTE: Google Maps will try to give you a map. It may not be what you expected.
' If you "guess" a city in a state, and there is NO such place, Google map
' will give you a result based on his algorithm. It may be in a totally
' different state or country.
'
Dim sLink As String
On Error GoTo StreetToGoogleMap_Error
' General gmap link -- NO Key required **********
sLink = "http://maps.google.com/maps?f=q&hl=en&q="
' a street address for sample map
' Sample addresses to try:
'MyStreet = " 25 James Street, Kingston,ON,CANADA"
'MyStreet = " 25 James Street, Kingston,NY,USA"
'MyStreet = " 25 James Street, Kingston,PA, USA"
'MyStreet = " 25 James Street, Kingston,California, USA"
'MyStreet = " 25 James Street, Kingston,California,90210, USA"
'******** N O T E **************************************
'*******************************************************
' Google maps insists on returning PA even though
' California was spelled out.
'
'When I added a 90210 Zip, Google maps recognized that the
'coordinates are not a valid address. He returns a message
'on a map of the USA.
'
'Msg from Maps
' We were not able to locate the address:
'25 James Street, Kingston, California, 90210, USA
'
'Would you like to:
'
' * Get a map of 25 James St, Kingston, PA 18704
'
'*************************************************
'********** B E A D V I S E D *****************
'Show map using MyStreet
Application.FollowHyperlink sLink & sAddr, , True
On Error GoTo 0
Exit Sub
StreetToGoogleMap_Error:
MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure StreetToGoogleMap"
End Sub
Here is a small routine to test the above procedure.
Code:
'---------------------------------------------------------------------------------------
' Procedure : JTestSAddr
' Author : Jack
' Created : 7/13/2011
' Purpose : Sample procedure to create a Google Map
' based on street address passed as an input parameter
'---------------------------------------------------------------------------------------
' Last Modified:
'
' Inputs: N/A
' Dependency: N/A
'------------------------------------------------------------------------------
'
Sub JTestSAddr()
Dim myStreet As String
On Error GoTo JTestSAddr_Error
' a street address for sample map
' Sample addresses to try:
'MyStreet = " 25 James Street, Kingston,ON,CANADA"
'MyStreet = " 25 James Street, Kingston,NY,USA"
'MyStreet = " 25 James Street, Kingston,PA, USA"
'MyStreet = " 25 James Street, Kingston,California, USA"
'MyStreet = " 25 James Street, Kingston,California,90210, USA"
'******** N O T E **************************************
'*******************************************************
' Google maps insists on returning PA even though
' California was spelled out.
'
'When I added a 90210 Zip, Google maps recognized that the
'coordinates are not a valid address. He returns a message
'on a map of the USA.
'
'Msg from Maps
' We were not able to locate the address:
'25 James Street, Kingston, California, 90210, USA
'
'Would you like to:
'
' * Get a map of 25 James St, Kingston, PA 18704
'
'*************************************************
'********** B E A D V I S E D *****************
myStreet = "50 Second Ave, Tucson, AZ"
StreetToGoogleMap (myStreet)
On Error GoTo 0
Exit Sub
JTestSAddr_Error:
MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure JTestSAddr of Module GoogleMapsEtc"
End Sub