[AccessD] Retrieve data from a URL.

Doug Steele dbdoug at gmail.com
Mon Feb 15 16:57:28 CST 2010


Thanks, Stuart - worked like a charm!

On Mon, Feb 15, 2010 at 2:03 PM, Stuart McLachlan <stuart at lexacorp.com.pg>wrote:

> If you are talking about using the URLDownloadToFile API function to get
> some XML into a
> file, it is a bit roundabout, but it's actually not that complicated, it's
> very fast and it'sby far the
> easiest way I've found to do it.
>
> See example below of looking up the location of an IP address using this
> technique
>
> --
> Stuart
>
> On 15 Feb 2010 at 12:19, Doug Steele wrote:
> >
> > Application.FollowHyperlink "
> > http://api.toodledo.com/api.php?method=getToken;userid=td4b703588b0844"
> >
> > Then I just get an Internet Explorer window with the xml showing it it.
>  I
> > found some code on the web which gets Yahoo stock prices saves them into
> a
> > text file, reads the file and parses it, but that seems a bit roundabout.
> >
>
>
> Option Compare Database
> Option Explicit
>
> Declare Function URLDownloadToFile Lib "urlmon" _
>   Alias "URLDownloadToFileA" _
>  (ByVal pCaller As Long, _
>   ByVal szURL As String, _
>   ByVal szFileName As String, _
>   ByVal dwReserved As Long, _
>   ByVal lpfnCB As Long) As Long
>
> Const ERROR_SUCCESS As Long = 0
> Const BINDF_GETNEWESTVERSION As Long = &H10
>
> Function GetIPLoc(IP As String) As String
> 'Gets CountryName for an IP address from the online
> 'database at http://www.ipinfodb.com
>   Dim strSourceUrl As String
>   Dim strLocalFile As String
>   Dim hfile As Long
>   Dim strText As String
>
>   strLocalFile = "c:\deleteme.htm"
>   strSourceUrl = "http://www.ipinfodb.com/ip_query.php?ip=" _
>         & IP & "&output=xml"
>
> 'Get URL
>   If URLDownloadToFile(0&, _
>        strSourceUrl, strLocalFile, _
>        BINDF_GETNEWESTVERSION, _
>        0&) = ERROR_SUCCESS Then
>      hfile = FreeFile
> 'Read in data from temp file
>      Open strLocalFile For Binary As #hfile
>         strText = Space$(LOF(hfile))
>         Get hfile, , strText
>      Close #hfile
> 'Delete temporary file
>      Kill strLocalFile
> Debug.Print strText
> 'Pares Country name out of returned XML
>      strText = Mid$(strText, InStr(strText, "<CountryName>") + 13)
>      strText = Left$(strText, InStr(strText, "</CountryName>") - 1)
>      GetIPLoc = strText
>
>   End If
> End Function
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>



More information about the AccessD mailing list