Hi, I have an excel document that uses the bing API to pull distance for zip codes. I have VBA code
I wanted to apply this to a access database. I have a tblzipcode with a list of all the zip codes. I wanted to put 2 lookup boxes in a form referencing this table. When selected I want another box to calculate distance.
The excel formula is =getDistance(G34,G35) with g34 and g35 being the two zip codes. How do I make this formula work in access? I tried just reference the text boxes txtzipcode1 and txtzipcode2 but it didnt work.
Can this be done? If so, what am I missing.
Code:
Function GetDistance(sPCode As String, ePcode As String) As Double
Dim t As String
Dim re As XMLHTTP
t = "http://dev.virtualearth.net/REST/V1/Routes/Driving?o=xml&wp.0=" & sPCode & "&wp.1=" & ePcode & "&avoid=minimizeTolls&du=mi&key=mykey"
Set re = New XMLHTTP
re.Open "get", t, False
re.send
Do
DoEvents
Loop Until re.readyState = 4
With re
s = Split(.responseText, "<TravelDistance>")
End With
GetDistance = Val(s(1))
End Function
Function GetTimeinMins(sPCode As String, ePcode As String) As Double
Dim t As String
Dim re As XMLHTTP
t = "http://dev.virtualearth.net/REST/V1/Routes/Driving?o=xml&wp.0=" & sPCode & "&wp.1=" & ePcode & "&avoid=minimizeTolls&du=mi&key=mykey"
Set re = New XMLHTTP
re.Open "get", t, False
re.send
Do
DoEvents
Loop Until re.readyState = 4
With re
s = Split(.responseText, "<TravelDuration>")
End With
GetDistance = Val(s(1)) / 60
End Function
The excel formula is =getDistance(G34,G35) with g34 and g35 being the two zip codes. How do I make this formula work in access? I tried just reference the text boxes txtzipcode1 and txtzipcode2 but it didnt work.
Can this be done? If so, what am I missing.