Web Service using Access VBA


Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

   Dim objXML              As Object
   Dim strURL              As String

   Set objXML = CreateObject("MSXML2.XMLHTTP")

   strURL = "http://www.weather.gov/xml/current_obs/"
'    strTest = "http://www.weather.gov/xml/current_obs/KBUF.xml"

   strURL = strURL & UCase(txtStation) & ".xml"
   objXML.Open "GET", strURL, False
   objXML.Send

   With objXML.responseXML
      txtWeather = "Location  = " & .SelectSingleNode("//location").Text & vbCrLf & _
        "Temp in F = " & .SelectSingleNode("//temp_f").Text & vbCrLf & _
        "Temp in C = " & .SelectSingleNode("//temp_c").Text & vbCrLf & _
        "Weather is " & .SelectSingleNode("//weather").Text
   End With

Exit_Command1_Click:
    Exit Sub

Err_Command1_Click:
    txtWeather = "ERROR " & Err.Description
    Resume Exit_Command1_Click

End Sub


To make this example work set weather.gov as a Trusted Site in Internet Explorer and set the secuity level for this zone to Low.