Print This Article Post Comment Add To Favorites Email to Friends Ezine Ready

How To Build A Simple Distance Checker Between Two Uk Postcodes Into Your Access Database In Vba

By: Michael Jillions Home | Computers-and-Technology


The ability to calculate the distance between two postcodes is of an enormous benefit in many software applications. There are online companies who can offer automated access to their distance check software but not only will this cost, but will rely on internet access as well. Here we will show you the code used to give you this facility.

This method will only calculate the distance in Kilometres (divide the result by 1.609344 for miles) as the crow files but it is extremely useful when, for instance, you are marketing everyone within a fixed radius.

So how do we do it? The method uses the Haversine formula which assumes that the Earth is a sphere. OK we know that the Earth is not a perfect sphere, but when you are checking between two map co-ordinates it is more than accurate enough for these purposes.

OK so without going into the technicalities of how the formula works, we shall get straight on with the coding requirements for VBA.

You will need a table in your application containing all the UK postcodes and their X & Y axis co-ordinates. We would be happy to provide this.

The following VBA Code attached to the Calculate Distance click event is used in a simple form where the user enters the start and end postcodes and the distance is calculated.

txtPostCodeStart and txtPostCodeEnd are blank text boxes for entering your criteria. txtStartLat, txtEndLat, txtStartLong and txtEndLong are text boxes that are automatically populated through the after update event on the text boxes txtPostCodeStart and txtPostCodeEnd using simple RecordSet vba programming.

Private Sub caldistance_Click() On Error GoTo Err_caldistance_Click

If Me.TxtPostCodeStart = "" Then MsgBox ("Please enter a Start Post Code") Exit Sub End If

If Me.TxtPostCodeEnd = "" Then MsgBox ("Please enter an End Post Code") Exit Sub End If

Distance = (Sin((Me.TxtEndLat * 3.14159265358979) / 180)) * (Sin((Me.TxtStartLat * _ 3.14159265358979) / 180)) + (Cos((Me.TxtEndLat * 3.14159265358979) / 180)) * _ ((Cos((Me.TxtStartLat * 3.14159265358979) / 180))) * _ (Cos((Me.TxtStartLong - Me.TxtEndLong) * (3.14159265358979 / 180)))

Distance = 6371 * (Atn(-Distance / Sqr(-Distance * Distance + 1)) + 2 * Atn(1))

Me.TxTDistance = Distance

Exit_caldistance_Click: Exit Sub

Err_caldistance_Click: MsgBox Err.Description Resume Exit_caldistance_Click End Sub

Whilst we have demonstrated a simple form, the basic formula is there to be used in a host of different ways. We hope you will find this as useful as we have and if you need any assistance please don't hesitate contact us or visit our website!



Article Source: http://www.eArticlesOnline.com

About the Author:
Michael Jillions is a Director for Mill House Data Solutions Ltd, specialists in the design of prefessional grade, bespoke software applications.
http://www.millhousedata.com


Tags: , , , , ,

Please Rate this Article

 

Not yet Rated

Click the XML Icon Above to Receive Computers-and-Technology Articles Via RSS!

Recent Related Articles From Computers-and-Technology

  • Automated Source Code Analysis Whitepaper
    By: Gwyn Fisher | Apr 20th 2009
    Abstract Syntax Trees
    An abstract syntax tree, or AST for short, is simply a tree-structured representation of the source code as might be typically generated by the preliminary parsing stages of a compiler.
    Read

  • Website Design Considerations I
    By: Computerman | Mar 21st 2008
    web design is relatively easy with such programs as Alley Code, Evrsoft, Coffee Cup, Page Breeze or other free html editors Read

  • Adopting Bug-hunting Tools While Staying Agile
    By: Gwyn Fisher | Apr 20th 2009
    While the Agile Manifesto’s principle of â€individuals and interactions over processes and tools†seems to de-emphasis the need for tools, Agile teams use many tools to support their development †including software configuration management tools, build management tools, requirements tracking tools, testing tools, pr ... Read

  • Agile Development - A Brief Introduction
    By: Gwyn Fisher | Jul 31st 2009
    Agile is based upon a number of guiding principles that all Agile teams follow. For the purposes of this discussion, three principles - or values - are of particular interest: Read

  • Fda Software Verification And Validation
    By: Todd Landry | Sep 7th 2009
    Main topic of today is using Agile in an FDA regulated medical device context. Sounds like an impossibility I know, but the folks from Agiletek and Abbott presented a very interesting case study on how they did it. Read

  • Static Analysis For Ruby And Python
    By: Todd Landry | Oct 3rd 2009
    As a developer of static analysis tool for mainstream statically-typed languages, like C++ and Java, I was wondering for quite a while about how well static analysis applies to dynamically-typed languages, like Ruby and Python. Read

  • Agile Development And Product Management
    By: Todd Landry | Nov 7th 2009
    Agile Product Management and a lively talk about modern software development by Alistair Cockburn were the themes of the day. Read

  • The Evil Packet Sniffer
    By: Eran Aharonovich | Dec 3rd 2006
    A "Packet Sniffer" is a utility that sniffs without modifying the network's packets in any way.

    By comparison, a firewall sees all of a computer's packet traffic as well, but it has the ability to block and drop any packets that its programming dictates. Packet sniffers merely watch, display, and log this tra ...
    Read

  • Rss Feed Etiquette
    By: Sharon Housley | Jan 29th 2008
    We felt it would be helpful to provide general guidelines for those constructing an RSS 2.0 feed. In general, the following are guidelines for constructing an RSS feed. It is good to get into the habit of validating the RSS feed, either with software, or with an online validator. Read

  • Perl Script Database
    By: Gupta | Jul 24th 2007
    Zipcode Finder is a comprehensive tool to find the zip code of any USA city/state. Also, users can enter their zip code to find out the cities or zip codes within a given distance from their zip code. Read


Copyright © 2005-2011 eArticlesOnline, LLC - All Rights Reserved
Terms of Service | Privacy Policy