Results 1 to 8 of 8
  1. #1
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398

    Calculating distance between 2 zip codes

    I import information pertaining to a shipment. I have to calculate the driving distance between 2 zip codes. Currently I go to mapquest, enter the two zip codes, then paste the distance within my DB. I've looked at applications that calculate the distance, but they do not calculate driving distance, which is what I need.



    I'd like to calculate the distance when the data is being imported in . I've looked at Google Maps, and here is what I have now.
    I've completed the beginning and ending of this process, I've created the http line and I've imported the xml data into my table

    Here's what I need help with

    This http request works:

    http://maps.googleapis.com/maps/api/...l&sensor=false

    How do I execute this http command within VBA, then save the results as an xml file?


    Thank you in advance!!
    Last edited by crowegreg; 04-27-2012 at 12:54 PM.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Never done anything like this and can't find much about VBA getting data from web page.

    That link is an xml file. If you want to save it out as a text file Google: Access VBA save web page as text file.

    Access 2010 offers a new webbrowser control.
    Review http://office.microsoft.com/en-us/ac...101631434.aspx

    Might be able to use it to open the link you show and then grab the text info from the page.
    This link has VB.net code as example of that.
    Hopefully could modify code to VBA syntax http://www.dreamincode.net/code/snippet5332.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    Thanks for your info. I'll see what I can do with it, and update the thread.

  4. #4
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    Here's what I have at this time:

    strhttp = "http://maps.googleapis.com/maps/api/...ix/xml?origins="
    strhttp = strhttp & strOZip & "&destinations="
    strhttp = strhttp & strDZip & "&units=imperial&sensor=false"


    Application.FollowHyperlink (strhttp)

    MsgBox "Determine the distance"

    'import xml file
    Application.ImportXML _
    DataSource:="c:\scat\zipxml.xml", _
    ImportOptions:=acStructureAndData

    This works, but it requires keyboard entries. When the Google API is executed, a Microsoft Office window pops up, it is asking if you want to open the file, I select ok. A new IE window opens with xml data that I have requested. I have to manually save the file. After saving the file, I close that IE window. You'll see that I have a msgbox come up so it halts the execution of the VBA so I can get that file saved. I select ok to my message, and the process is completed.

    So what I'm needing is:
    How do I prevent or automatically answer the Microsoft Office message?
    How do I automatically save the the XML file?
    I can live with the msgbox being displayed, but if their is something better, I'm all for it.

    Thanks in advance!!

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Double posting/Cross posting is frowned upon

    You should at least advise the reader of the other post(s) so that volunteer time is not wasted.

    If we don't know about the replicated posts, we may spend time solving/helping, that has already been resolved.

    If readers are aware of other posts, they can follow various threads/responses, and possibly learn.

    http://www.access-programmers.co.uk/...d.php?t=225339

    Please read: http://www.excelguru.ca/content.php?184

  6. #6
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    I don't know how it got double posted.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    see post #5 at http://www.access-programmers.co.uk/...83#post1150683

    Sample database (mdb) included.
    Last edited by orange; 05-01-2012 at 07:04 AM.

  8. #8
    mbenton's Avatar
    mbenton is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Posts
    73
    This post helped my through a project, thanks. I do have a question...I can use this distance calculator if I can change the speed to 45mph. Can you explain how this can be done? Thank you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Google Distance Matrix API
    By rbiggs in forum Programming
    Replies: 2
    Last Post: 07-11-2011, 06:51 AM
  2. Consolidation codes from different table.
    By suverman in forum Queries
    Replies: 3
    Last Post: 05-13-2011, 10:39 AM
  3. Zip Codes
    By Laurie B. in forum Access
    Replies: 6
    Last Post: 02-25-2011, 02:38 PM
  4. Multiple events per location Distance tables
    By flebber in forum Database Design
    Replies: 1
    Last Post: 03-13-2010, 08:48 PM
  5. Top 3 times for each distance
    By CraigBFG in forum Queries
    Replies: 0
    Last Post: 06-24-2009, 09:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums