magmike wrote:
I'd like to set up an event procedure that when the city field is
double clicked they are sped away to a google map showing directions
and distance from our city (nashville) to the client city. The link is
as follows, but I can't figure out how to implement it:
http://maps.google.com/maps?f=d&hl=e...lle,+TN&daddr=[City],+[State]&sll=36.047349,-86.716609&sspn=0.0072,0.014462&ie=UTF8&z=9&om=1
Thanks for your help!
From a post a year or two ago I read in this group I came up with this
method. I pass to MakeUrl the arguments "Map" or "Driving". If "Map",
it creates just the map of the FROM address, if driving it has the
directions for the FROM to TO addresses.
I have a form with a "FROM" Address, city, state, zip as well as the
same for the TO fields. Press the command button to present the values.
I also added a command button to swap the From/To values on the form
even tho I could have passed an argument in the URL to present reverse
directions.
I do require both city and state in the form. I really don't care about
the zip but you can mod the code to whatever. Beyond that, if you have
a form with from/to fields using the field names in the routine then
this code should run without a hitch.
Private Sub MakeURL(strType As String)
On Error GoTo Err_MakeURL
Dim strURL As String
Dim objBrowser As Object
If IsNull(Me.City) Or IsNull(Me.State) Then
MsgBox "You need to supply at least the city and state.", ,
"Missing Info"
Me.City.SetFocus
ElseIf strType = "Driving" And (IsNull(Me.ToCity) Or
IsNull(Me.ToState)) Then
MsgBox "You need to supply at least eding city and state for
driving directions.", , "Missing Info"
Me.ToCity.SetFocus
Else
'Declare variables.
strURL = CreateUrl(Me.Address, Me.City, Me.State, Me.ZipCode)
If strType = "Driving" Then
strURL = strURL & "+" & "to" & "+" &
CreateUrl(Me.ToAddress, Me.ToCity, Me.ToState, Me.ToZipCode)
End If
strURL = "http://maps.google.com/maps?q=" & strURL &
"&iwloc=A&hl=en"
Dim obj As Object
Set obj = CreateObject("InternetExplorer.Application")
With obj
.Navigate2 strURL
.Visible = True
End With
Set obj = Nothing
End If
Exit_MakeURL:
Exit Sub
Err_MakeURL:
MsgBox Err.Description
Resume Exit_MakeURL
End Sub
Private Function CreateUrl(strAddress As Variant, strCity As String,
strState As String, strZip As Variant) As String
'generate the URL to pass to Google in browser.
Dim strURL As String
Dim strOrig As String
Dim intPos As Integer
If Not IsNull(strAddress) Then
strOrig = strAddress
Do While True
If strOrig <"" Then
intPos = InStr(strOrig, " ")
If intPos 0 Then
strURL = strURL & Left(strOrig, intPos - 1) & "+"
strOrig = LTrim(Mid(strOrig, intPos + 1))
Else
strURL = strURL & strOrig & "+"
Exit Do
End If
Else
Exit Do
End If
Loop
End If
strURL = strURL & strCity & "+" & strState & "+"
If Not IsNull(strZip) Then strURL = strURL & strZip & "+"
CreateUrl = Left(strURL, Len(strURL) - 1)
End Function