I am trying to code an access database that will allow a user to input two zip codes and return the distance in miles between the two. I have a table that lists the zip codes with the latitudes and longitudes. Below is the code that I have so far. Any help would be great.
DB= zipcodes
Table = ZIP Codes
Fields = ZIP Code, Latitude, Longitude
On the form I have two text boxes to enter info called txtZipCode1, txtZipCode2
Private Sub cmdCalculateDistance_Click()
Dim dbsZipCodes As Database
Dim rstTable As Recordset
Dim rstZip1 As Recordset
Dim rstZip2 As Recordset
Dim rstLatitude1 As Recordset
Dim rstLatitude2 As Recordset
Dim rstLongitude1 As Recordset
Dim rstLongitude2 As Recordset
Set dbsZipCodes = CurrentDb
With dbsZipCodes
'Open the Recordset objects
Set rstTable = .OpenRecordset("Zip Codes", dbOpenTable)
Set rstZip1 = dbsZipCodes.OpenRecordset("ZIP Codes")
Set rstZip2 = dbsZipCodes.OpenRecordset("ZIP Codes")
rstZip1.Index = "PrimaryKey"
rstZip1.Seek "=", txtZipCode1
rstLatitude1.Index = "PrimaryKey"
rstLatitude1.Seek "=", Latitude
MsgBox rstLatitude1
If rstZip1.NoMatch Or rstZip2.NoMatch Then
MsgBox "No Match"
Else
End If
rstZip1.Close
rstZip2.Close
dbsZipCodes.Close
Set rstZip1 = Nothing
Set dbsZipCodes = Nothing
End With
End Sub
DB= zipcodes
Table = ZIP Codes
Fields = ZIP Code, Latitude, Longitude
On the form I have two text boxes to enter info called txtZipCode1, txtZipCode2
Private Sub cmdCalculateDistance_Click()
Dim dbsZipCodes As Database
Dim rstTable As Recordset
Dim rstZip1 As Recordset
Dim rstZip2 As Recordset
Dim rstLatitude1 As Recordset
Dim rstLatitude2 As Recordset
Dim rstLongitude1 As Recordset
Dim rstLongitude2 As Recordset
Set dbsZipCodes = CurrentDb
With dbsZipCodes
'Open the Recordset objects
Set rstTable = .OpenRecordset("Zip Codes", dbOpenTable)
Set rstZip1 = dbsZipCodes.OpenRecordset("ZIP Codes")
Set rstZip2 = dbsZipCodes.OpenRecordset("ZIP Codes")
rstZip1.Index = "PrimaryKey"
rstZip1.Seek "=", txtZipCode1
rstLatitude1.Index = "PrimaryKey"
rstLatitude1.Seek "=", Latitude
MsgBox rstLatitude1
If rstZip1.NoMatch Or rstZip2.NoMatch Then
MsgBox "No Match"
Else
End If
rstZip1.Close
rstZip2.Close
dbsZipCodes.Close
Set rstZip1 = Nothing
Set dbsZipCodes = Nothing
End With
End Sub