That's a very interesting technique. Thanks for sharing it with us.
You might be interested in a routine I developed many years ago (I think it
was in dBASE originally) for finding locations in a particular area. It
won't be of practical use in many commercial situations as it was done in the
context of my own work in environmental planning and does require that each
location be identified by map references (an easting and northing value in
the UK national grid) and a site radius value indicating the nominal extent
of the site. The way it worked was that the user entered a grid reference
and search radius, and the routine then located any sites which fell within
the intersections of the two circles defined by the site's grid
reference/radius and the user entered grid reference/radius. This is the
snippet of the relevant code from the Click event procedure of a button on
the dialogue form:
Dim strEast As String, strNorth As String
If RadialValue = "" Or IsNull(RadialValue) Then
'Display message if no radius entered
MsgBox "No radius entered", vbExclamation, "Invalid
Operation"
Me!RadialValue.SetFocus
Else
'Calculate filter string
' Call Easting and Northing functions and convert results to
strings
strEast = Str(Easting(RadialNgr))
strNorth = Str(Northing(RadialNgr))
strFilter = strFilter & "(Sqr((Easting - " & strEast & _
")^2 + (Northing - " & strNorth & ")^2) < " & _
RadialValue & " + Radius) "
strFilterText = "Radial search of " & RadialValue & _
"m on " & RadialNgr & " "
End If
As you can see its really just a simple application of Pythagoras's theorem.
The strFilter variable is then used to filter a form or report. The code
calls these functions:
Public Function Easting(strNgr As String) As Double
Dim lngEastSquare As Long, lngEastDetail As Long
' Get numeric value of easting 100km square
Select Case Left(strNgr, 2)
Case "SJ"
lngEastSquare = 300000
Case "SK"
lngEastSquare = 400000
Case "SO"
lngEastSquare = 300000
Case "SP"
lngEastSquare = 400000
Case Else
lngEastSquare = 0
End Select
lngEastDetail = Val(Mid(strNgr, 3, 5))
Easting = Val(lngEastSquare + lngEastDetail)
End Function
Public Function Northing(strNgr As String) As Double
Dim lngNorthSquare As Long, lngNorthDetail As Long
' Get numeric value of northing 100km square
Select Case Left(strNgr, 2)
Case "SJ"
lngNorthSquare = 300000
Case "SK"
lngNorthSquare = 300000
Case "SO"
lngNorthSquare = 200000
Case "SP"
lngNorthSquare = 200000
Case Else
lngNorthSquare = 0
End Select
lngNorthDetail = Val(Mid(strNgr, 8, 5))
Northing = Val(lngNorthSquare + lngNorthDetail)
End Function
In each case the grid square letters are those for our particular area, but
if it were adapted to cover the whole of the UK these could be in a separate
table and looked up rather than hard-coded, which is of course bad technique
as data should only be held in tables, but I was young and green then! These
functions are used to enable the user to enter a grid reference in the
conventional format with which people here are familiar, of two letters
followed by a string of digits, whereas the grid references are stored in the
table as two completely numeric values, which are much better for doing
calculations.
Using geometry like this only works with relatively small areas of course.
In our case we were only interested in distances of 200km or less, but it
would work over the whole UK satisfactorily within an acceptable margin of
error. For global use using latitude and longitude values it would be
necessary to use spherical trigonometry rather than geometry. I've seen code
to do this, but never had occasion to use it.
The above and other associated routines became largely redundant when we
started using a GIS, where we simply clicked on a map on the screen, but they
served us well for a long time.
Ken Sheridan
Stafford, England
Hi Ken,
When you say 'user location' are you saying that it’s the location of the
customer which determines which supplier companies are returned by the combo
[quoted text clipped - 4 lines]
bit like the 'store finder' facility one often sees on company web sites
where by entering your post code you get a list of local branches.
Yes, that's right. That was an easy fix as it was determined by the Users
location. That's one problem fix on one form............
You are quite right, the two correlated combo box solutions in my demo (one
for single forms, the other for continuous forms) would work for the OP, but
[quoted text clipped - 13 lines]
Ken Sheridan
Stafford, England
but a problem in another form I had was that the Form has only one
field/control. Having more fields was not what they wanted (ugly). In this
case, you can't use Users location where companies does not fall into this
category. The Company had two addresses in one Country in two City. The
combobox was not good enough as Users might still pick the wrong one.
I had to create a Popup Filter Form with 4 auto cascade unbound comboboxes,
CompanyName bound to ID, City, Country, Region and one ListBox. When the
Users pick the combos, the Listbox will show the Companies. All the Users had
to do was to narrow down the list to one company from the combos and the
Popup will return the value to the field/control. At least it was acceptable
the Users.