Download Image from website (1 Viewer)

mlh407

Registered User.
Local time
Today, 06:43
Joined
Jun 24, 2005
Messages
26
Hi Everyone,
Is there a way for me, using access, to press a button and download an image from a website. Then display that image inside an access form?

Thanks,
Michael
 

ByteMyzer

AWF VIP
Local time
Today, 06:43
Joined
May 3, 2004
Messages
1,385
There is. One method uses the ADODB.Stream object and the xmlHTTP object to retrieve the file from the web and to save it to your computer.

Create a new Module, paste the following text into it and save the module as modHtthGet:
Code:
Option Compare Database
Option Explicit

Const adTypeBinary = 1
Const adSaveCreateOverwrite = 2
Const adModeReadWrite = 3

Public Sub httpGet(sourcePath As String, destinationPath As String)

    Dim xmlHTTP
    Dim contents
    Dim oStr

    Set xmlHTTP = CreateObject("Microsoft.XMLHTTP")
    xmlHTTP.Open "GET", sourcePath, False
    xmlHTTP.send
    contents = xmlHTTP.responseBody

    Set oStr = CreateObject("ADODB.Stream")
    oStr.Mode = adModeReadWrite
    oStr.Type = adTypeBinary
    oStr.Open

    oStr.Write (contents)
    oStr.SaveToFile destinationPath, adSaveCreateOverwrite

End Sub
You can call this sub with something like:
Code:
httpGet "http://i2.microsoft.com/h/all/i/ms_masthead_8x6a_ltr.jpg", _
"C:\ms_masthead_8x6a_ltr.jpg"
See if this works for you.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom