Link to home
Start Free TrialLog in
Avatar of douglaskarr
douglaskarr

asked on

Write a function "GetDistance" in a module in Access

I would like to be able to write GetDistance(startLatitude, startLongitude, endLatitude, endLongitude)

GetDistance = 3959 * ACOS(
        ( SIN(startLatitude / 57.3) * SIN(endLatitude / 57.3))
        + (COS(startLatitude / 57.3)
        * COS(endLatitude / 57.3)
        * COS((startLongitude - endLongitude) / 57.3)))

Please write a function in a module that I can do that.
nTop = integer
startLatitude = double
startLongitude = double
endLatitude = double
endLongitude = double

In the end, I would like to be able to write a query ....

Select TOP 25 * where getDistance(lat, long, 23.4, 45.7) < 5 from Table
ASKER CERTIFIED SOLUTION
Avatar of MotelKamzoil
MotelKamzoil

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 1William
1William

Yes, you can call a function inside of VBA SQL!
I'm sorry, I didn't know that. I'm used to working with MySQL/PHP, Access is kind of a new thing for me. Thank you very much, 1William!

I think my function is still valid, though. You just want to double-check the math.
<looking the other way...>  Math..  Yikes!