Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

Link to MapQuest

I created a database which stores contacts (information gathered from business cards).  To query, users enter the data into fields on a standard form and then presented results via another form.

I wish to place a button next to the contacts address.  when pressed, the button would link to mapquest and provide directions.  The originating point will alway be the same soe it could be hard coded, the only dynamic portion would be the destination (which will come from the database)

Any Ideas?
  • 6
1 Solution

the above link will take you to directions from:
101 StartAddress CityName,NC 27615

101 EndAddress CityName,NC 27615

try using that to dynamically build your link, remember, anywhere there is a space in your address you have to put "+" in instead of that, so you will have to parse out all of the spaces and add + instead
Here's the all the code that I used, it works! I tried it.  You may want to try it for different regions of the country.

Private Sub btnGetDirections_Click()
Dim link As String
Dim address As String
Dim city As String
Dim state As String
Dim zip As String
Dim startaddress As String
Dim startcity As String
Dim startstate As String
Dim startzip As String
startaddress = "101+Start+Address+Ln"
startcity = "Starting+City"
startstate = "NC"
startzip = "27587"
address = DeleteWithin(Me.txtAddress, " ")
city = DeleteWithin(Me.txtCity, " ")
state = Me.txtState
zip = Me.txtZip
link = "http://www.mapquest.com/directions/main.adp?go=1&1a=" & startaddress & "&1c=" & startcity & "&1s=" & startstate & "&1z=" & startzip & "&2ahXX=&2y=US&2a=" & address & "&2c=" & city & "&2s=" & state & "&2z=" & zip
FollowHyperlink link, , True, False
End Sub

Private Function DeleteWithin(ByVal TheString As String, ByVal BadTerm As String)
If InStr(TheString, BadTerm) > 0 Then
    Dim oldlength As Integer, totallength As Integer, innerstringpos As Integer
    Dim leftside As String, rightside As String
    oldlength = Len(BadTerm)
    totallength = Len(TheString)
    innerstringpos = InStr(TheString, BadTerm)
    leftside = Left(TheString, innerstringpos - 1)
    rightside = Right(TheString, totallength - (innerstringpos + oldlength - 1))
    TheString = leftside & "+" & rightside
    DeleteWithin = TheString
End If
End Function
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

I would appreciate you upping the points on this question for all the work that was put into this answer, but it's up to you
chaddcarrAuthor Commented:
No problem with the points.... however, one more question.  Am I simply cutting and pasting the above script into the code of a button?

That's what I'd do, I had that in a button click event, I also have a version of it that will pull both the start and the end date if you want both of them.
Let me clarify that...the function "DeleteWithin" needs to be by itself, it can't be within a button click event procedure.  only what you see between the
"Private Sub btnGetDirections_Click()"
and the
"End Sub"

should go in a button click.  Let me know if you have any more questions.

by the way: the sub is assuming that you have 4 textboxes called:

if you have something else let me know.  If I were you I'd make state a combobox of all the state names, to prevent errors.  if you do that, just name the combobox txtstate and it will all still work the same as long as the bound column will return the two letter equivalent of the state

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now