Page 1 of 4 1234 LastLast
Results 1 to 15 of 47
  1. #1
    hinsdale1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Apr 2013
    Posts
    63

    Access VBA to incorporate a web service (weather) ?

    Upfront warning: worthless newbie

    I found a video tutorial for Excel users to incorporate current 5 day weather into spreadsheet via web service. I would like to replicate the identical format but for an Access form?

    http://www.youtube.com/watch?v=uo5TvtXuzJQ




    Unfortunately, just the starting thoughts of attempting to convert this code for use in Access almost made my head explode. This is well above my pay grade.

    Any chance someone of masterful intellect could make quick work of this vba coding to accomplish something like this? then I could just create the relevant text boxes, image controls on my form to receive the vba output ?

    This is obviously asking a lot.. if anyone can help I would be eternally grateful. Although I would prefer the whole 5 day (/w images) shebang, if I can just get the text for current day hi and lows to load would be better than nothing.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not sure what you really need. Access has a Web control that allows embedding web pages on a form. http://office.microsoft.com/en-us/ac...101631434.aspx
    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
    hinsdale1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Apr 2013
    Posts
    63
    Cant seem to find the web control in Access 2013 and I am not sure its what i am looking for anyway.

    I would like to parse data for use in the form from a webpage or web service (API).

    For instance, I would like - on form load - to retrieve (and display in appropriate fields on the form) just the high temps (top of column) from the 7AM 10AM 1PM 4PM 7PM columns from a website(service) like this :

    http://igoogle.wunderground.com/cgi-...=iGoogle&hl=en

    Anyone know how to accomplish something like this?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Fairly certain this has been asked before. Review https://www.accessforums.net/program...rol-30367.html
    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.

  5. #5
    hinsdale1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Apr 2013
    Posts
    63
    Well unfortunately as I said I don't seem to be able to locate any Web browser control (i have Access 2013). And to further reaffirm my general stupidity, again the link you have provided in answer to one of my questions does not seem to provide me anything that my pea brain can seem to relate to a solution.

    Perhaps it is that processes that seem obvious or self explanatory to someone that has worked with access and vba are not so obvious to those of us unfamiliar.

    So I would be very grateful to anyone that might share with me a suggestion of a general concept for what might be done and then even give me a little taste of the type of code I might use to accomplish? this it would go along ways toward getting me there....

    I am hoping to retrieve (and display in appropriate fields on the form) just the high temps (top of column) from the 7AM 10AM 1PM 4PM 7PM columns from a website(service) like this :

    http://igoogle.wunderground.com/cgi-...=iGoogle&hl=en

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I know, not much out there on this topic. There are some (weak) clues in the thread I referenced but not really enough.

    This tutorial shows how to install web browser control on form http://office.microsoft.com/en-us/ac...239.aspx?CTT=1

    The Web Browser control icon looks like a web page with a world globe image on it.

    I followed the steps and was able to install web page within the control. Not sure how to pull data from the web page. I know I've been through this with someone but will never find that thread again. Sounds like an interesting project for this weekend. See what I can come up with.

    I see that Wunderground also offers an API interface located under their Weather tab > Downloads.
    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.

  7. #7
    hinsdale1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Apr 2013
    Posts
    63
    Quote Originally Posted by June7 View Post
    Sounds like an interesting project for this weekend. See what I can come up with.

    I see that Wunderground also offers an API interface located under their Weather tab > Downloads.
    It seems that no amount of search/reading is improving my clarity into this problem and, in fact, it may even be making it worse. So I am stuck. Therefore, news of your upcoming efforts at cracking the case could not have come at a better time. Thanks June and I am , of course, wishing you great success!

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I think at least two ways to pull this data from web page. Neither requires the Web Browser control.

    1. VBA code opens the web page as an Internet Explorer object. Requires VBA reference to Microsoft Internet Controls. Does not require an API account. This was the method I originally had in mind.

    2. VBA uses website's API interface, requires an account and a key code and VBA reference to Microsoft XML.

    Got this much to work with Wunderground:
    Dim Req As New XMLHTTP
    Dim Resp As New DOMDocument
    Dim Weather As IXMLDOMNode
    Req.Open "GET", "http://api.wunderground.com/api/YOUR KEY CODE HERE/forecast10day/q/CA/San_Francisco.xml", False
    Req.Send
    Debug.Print Req.responseText

    Unfortunately, I am not seeing a 5-day forecast parameter with the Wunderground API. I see a 10-day but the XML structure is really different from the video example. Switched to WorldWeatherOnline because have a working example in the video and seems to offer more help tools.

    I set up a form with 5 controls for each data element (date, day, max temp, min temp, image). Gave them names like: Date1, Date2, etc. I set format property for the date textboxes as mm/dd/yyyy. Set format property for the day textboxes as ddd and ControlSource of =Date1, etc.
    Code:
    Private Sub btnRefresh_Click()
    Dim Req As New XMLHTTP
    Dim Resp As New DOMDocument
    Dim Weather As IXMLDOMNode
    Dim i As Integer
    'WorldWeatherOnline API, could not get the syntax from video to work, the second version is from the website
    ''Req.Open "GET", "http://free.worldweatheronline.com/feed/weather.ashx?q=CITY NAME HERE&format=xml&num_of_days=5&key=YOUR KEY CODE HERE", False
    Req.Open "GET", "http://api.worldweatheronline.com/free/v1/weather.ashx?q=CITY NAME HERE&format=xml&num_of_days=5&key=YOUR KEY CODE HERE", False
    Req.Send
    Resp.LoadXML Req.responseText
    For Each Weather In Resp.getElementsByTagName("weather")
        i = i + 1
        Me.Controls("Date" & i) = CDate(Weather.SelectNodes("date")(0).Text)
        Me.Controls("Hi" & i) = Weather.SelectNodes("tempMaxF")(0).Text
        Me.Controls("Lo" & i) = Weather.SelectNodes("tempMinF")(0).Text
        ''Me.Controls("Image" & i).Picture = Weather.SelectNodes("weatherIconUrl").Item(0).Text
    Next
    End Sub
    If the city name is multiple words, spaces must be replaced.
    Wunderground example: San_Francisco
    World example: san+diego

    What I am stuck on is getting the images to display. I tried Image controls and setting the Picture property. I don't think the Image control ControlSource property can be set with VBA, found that out helping another poster. VBA gets the URL string but then just errors 'Microsoft Access can't open the file'. I read one source that says image must be a jpg. These weather images are png files. I also did a test with a spreadsheet and that works.

    If you want to write data to a table instead of into controls on form, there are ways to do that.
    Last edited by June7; 05-05-2013 at 12:14 PM.
    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.

  9. #9
    hinsdale1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Apr 2013
    Posts
    63
    Nice work June! Im thrilled you got it going. I am out of town this weekend until this evening so I haven't been able to test things out and see if I can get it working but looks very promising .

    I will be happy to get any local weather data feeding into my database but in a perfect world I would love to get the forecast High temps for the particular hours (7AM, 10AM, 1PM 4PM, 7PM) from the wunderground webpage I have linked above. Do you think it will be a huge leap to try to adapt to parse data from a webpage?

    Thanks again.. you're genius.

  10. #10
    hinsdale1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Apr 2013
    Posts
    63
    It all works great June1 (except the images) - really excited to have this functionality.

    Trying to look into possible fixes for the image problem but not having a lot of luck yet (I'm just on a short lunch break).

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    As I said, Wunderground didn't offer a 5-day forecast, weird, but that's what I saw. I don't know about pulling data for specific time of day from either site.

    Get a handle on referencing nodes of the xml file structure and could pull data from whichever you want. The Wunderground xml looked a little more complicated.

    The only idea I have about getting the images to display would be to download the images and rename like Image1, Image2, etc. Then set the Image control ControlSource property to: ="path\Image1", ="path\Image2", etc. Each refresh of the data would download the images and replace the previous downloaded images. I just don't know how or if the images can be downloaded.
    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.

  12. #12
    hinsdale1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Apr 2013
    Posts
    63
    Quote Originally Posted by June7 View Post

    The only idea I have about getting the images to display would be to download the images and rename like Image1, Image2, etc. Then set the Image control ControlSource property to: ="path\Image1", ="path\Image2", etc. Each refresh of the data would download the images and replace the previous downloaded images. I just don't know how or if the images can be downloaded.
    For some reason I cannot quite grasp your concept - can you explain your idea a little more specifically?


    The only idea I have been able to come up with is..

    because there are only a limited number of images (sunny, partycloudy,etc) it would not be difficult to locate,download, store locally all relevant images and then figure out a way to replace the url path of the url image assigned to the forecast with the local path to the locally stored image.

    Change

    http://www.worldweatheronline.com/im...0001_sunny.png

    To:

    \\NAS\share\pictures\wsymbol_0001_sunny.png


    What do you think of that option and do you have any insights into coding to allow me to replace the path?

  13. #13
    hinsdale1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Apr 2013
    Posts
    63
    Quote Originally Posted by June7 View Post
    What I am stuck on is getting the images to display. I tried Image controls and setting the Picture property. I don't think the Image control ControlSource property can be set with VBA, found that out helping another poster. VBA gets the URL string but then just errors 'Microsoft Access can't open the file'. I read one source that says image must be a jpg. These weather images are png files. I also did a test with a spreadsheet and that works.
    Well i found a relatively simply way to display images from the web in access. Installed an ActiveX control somebody wrote to handle images in Access, that has been updated to handle url images.

    http://access.bukrek.net/

    EDIT: Not sure of the limitations of this ActiveX control without purchase - only tested it loading one image from a url one time - havent played with it much.

  14. #14
    AlexHedley's Avatar
    AlexHedley is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    England
    Posts
    180

    Access VBA to incorporate a web service (weather) ?

    It might be a little ott but you could use a browser control and set it to the URL of the webpage image.

    BrowserControl.Navigate URL

    [http://office.microsoft.com/en-us/ac...01814124.aspx]


    Have you tried setting the .picture property to the URL of an image control?

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I tried both Picture and ControlSource properties with a static URL string and Access errored "could not load the file".
    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.

Page 1 of 4 1234 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Weather 'Gadget' on my Access Form
    By MFS in forum Programming
    Replies: 2
    Last Post: 02-21-2013, 04:25 PM
  2. Access web service com add-in problem
    By ballybeg in forum Programming
    Replies: 0
    Last Post: 03-24-2012, 01:43 AM
  3. Replies: 1
    Last Post: 02-08-2012, 01:33 PM
  4. Weather Information
    By chadshowalter in forum Import/Export Data
    Replies: 0
    Last Post: 02-23-2011, 03:40 PM
  5. Weather by Zip Code
    By graviz in forum Programming
    Replies: 0
    Last Post: 10-26-2009, 01:24 PM

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