<% Option Explicit Dim strSearch Set Connection = Server.CreateObject("ADODB.Connection") Connection.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=D:\inetpub\virtual\bridgetsoferin\WWWROOT\CGI-BIN\Distance\us_zip.mdb" %>
Locate a Retailer by Zip Code

To find the retailer closest to you, enter your zip code below.

Please Note: After clicking 'Find', it will take a few moments to find the retailer closest to the specified zip code. Thank you for your patience!

<%=Request("distance")%>"> Find Stores Within Of Your Zip

Back to main Locate a Retailer page

<% DIM SQL1, SQL2, sql_list, objRS1, objRS2, ziplist DIM mydistance, connection, totaldealers, dealers, total_distance,total_dist,shops IF Request.QueryString("Search") <> "" Then Set Connection = Server.CreateObject("ADODB.Connection") Connection.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=D:\inetpub\virtual\bridgetsoferin\WWWROOT\CGI-BIN\Distance\us_zip.mdb" 'check if the postal code submitted is in valid format IF IsNumeric(left(Request.QueryString("Search"),5)) = false then Response.Write("Please enter a properly formed postal code.") Else 'grab the location of the user's submitted postal code SQL1 = "SELECT * From US_ZIP where zip= '" & Request.QueryString("Search") & "'" Set objRS1 = Connection.Execute(SQL1) 'get a list of locations for all of our dealers by joining on ZIP 'SQL_list = "SELECT Latitude, Longitude, address, city, state, zip, email, directions " SQL_list = "SELECT * From Dealers INNER JOIN US_ZIP ON Dealers.ZIP = US_ZIP.ZIP order by US_ZIP.ZIP" 'Response.Write(SQL_list) 'Response.End set objRS2 = Connection.Execute(SQL_list) 'Set distance = Server.CreateObject("calculate.dist") totaldealers = 0 Do while not objRS2.eof IF Not objRS1.EOF Then 'compare the submitted location with each item in our dealer list and return the distance total_distance = round(distance(objRS1("Latitude"),objRS1("Longitude"),objRS2("Latitude"),objRS2("Longitude"),"miles"),1) 'total_dist = round(total_distance,1) Else Response.Write("Your postal code was not found in our current table.") Response.End End IF '=======Change distance here==========' If Request("distance") > 20000 Then Response.Write("Please enter a smaller distance.") Response.End End IF '=======Change distance here==========' IF total_distance =< cInt(Request("distance")) Then shops = shops & "" shops = shops & "" & objRS2("DealerName") & " " 'if total_distance <> "0" then shops=shops&"[Directions To us]" 'end if 'if objrs2("email") <> "" then shops=shops&"
Email" 'end if shops = shops & "
" & objRS2("Address") shops = shops & "
" & objRS2("City") shops = shops & "
" & objRS2("State") shops = shops & "
" & objRS2("ZIP") shops = shops & "
" & objRS2("website") shops = shops & "
" & "More Details" if total_distance <> "0" then shops = shops & "

This store is approximately " & total_distance & " miles from this zip code." Else shops = shops & "

The store is located within the same zip code." End if shops = shops & "
" & "
" 'shops = shops & "" totaldealers = totaldealers + 1 End IF objRS2.movenext Loop 'Give a total for shops found within this distance Response.Write("" & totaldealers) Response.Write(" Shops within ") & Request("distance") & (" Miles ") Response.Write("of " & objRS1("zip_name") & ", " & objRS1("state_abbr")) 'if we have 1 or more shops that are valid, write the results to the page If totaldealers > 0 Then Response.Write("

") Response.Write(shops) Response.Write("
") End If End IF Connection.Close End IF %>