display image residing on a web server??

deBassMan

Registered User.
Local time
Today, 17:07
Joined
Jul 25, 2006
Messages
56
Hi all

I would like to display an image on a form - but the image is held on a web server

any thoughts ...?
 
Paste the following code into a new Module:
Code:
Public Function GetHTTPPicture(ByVal sUrl As String, ByRef ctl As Control)

    Dim byteData() As Byte
    Dim XMLHTTP As Object

    Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")

    XMLHTTP.Open "GET", sUrl, False
    XMLHTTP.send
    byteData = XMLHTTP.responseBody

    Set XMLHTTP = Nothing

    sUrl = Environ("Temp") & "\" & Mid(sUrl, InStrRev(sUrl, "/") + 1)
    Open Environ("Temp") & "\" & sUrl For Binary Access Write As #1
        Put #1, , byteData
    Close #1

    ctl.Picture = sUrl

    Kill sUrl

End Function

Example: To use the function to populate an image control named Image1 in form Form1 with the image http://www.mysite.com/image.jpg, insert the following line of code into the appropriate sub/function in the form's code module:
Code:
GetHTTPPicture "http://www.mysite.com/image.jpg", Me.Image1

See if this method works for you.
 
Oops, here's the corrected function:
Code:
Public Function GetHTTPPicture(ByVal sUrl As String, ByRef ctl As Control)

    Dim byteData() As Byte
    Dim XMLHTTP As Object

    Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")

    XMLHTTP.Open "GET", sUrl, False
    XMLHTTP.send
    byteData = XMLHTTP.responseBody

    Set XMLHTTP = Nothing

    sUrl = Environ("Temp") & "\" & Mid(sUrl, InStrRev(sUrl, "/") + 1)
    [b]Open sUrl For Binary Access Write As #1[/b]
        Put #1, , byteData
    Close #1

    ctl.Picture = sUrl

    Kill sUrl

End Function
 
that is brilliant!

how did u learn about this stuff?
where is it documented?

how have u used this?

cheers
 
deBassMan said:
how did u learn about this stuff?

I designed a multi-carrier shipping application for a client entirely in Microsoft Access, using the respective Carriers' XML APIs to transmit transaction requests and retrieve the server responses. To accomplish this I had to study up on XML object manipulation (parsing/compiling) in Visual Basic with the DOMDocument object as well as transmitting web requests and retrieving web responses with the XMLHTTP object.

deBassMan said:
where is it documented?

There is plenty of material on the Web dealing with using the DOMDocument and XMLHTTP objects in Visual Basic.

deBassMan said:
how have u used this?

I've used it as I described in the application above, as well as for downloading files from the web (HTTP, FTP, etc.) from within an application.
 
method for bound images?

I'm building a database to organize information about my friends on MySpace. I want to enter an image URL for each record and enable Access to display these pictures in forms/reports. Is this possible?

I'm guessing that this xmlhttp method might be a good place to start, but I have no idea.
 

Users who are viewing this thread

Back
Top Bottom