trying to show an image from a URL (1 Viewer)

FireStrike

Registered User.
Local time
Yesterday, 23:24
Joined
Jul 14, 2006
Messages
69
I have a form that has an image name. The image is stored on a web server. The image can be accessed through a URL. The problem is how can I show the image on my form. When I try to change the picture property of my image control it tells me that it cannot use a web address. Any help would be greatly appriciated
 

RuralGuy

AWF VIP
Local time
Yesterday, 21:24
Joined
Jul 2, 2005
Messages
13,826
Have you tried using the Browser Control yet?
 

FireStrike

Registered User.
Local time
Yesterday, 23:24
Joined
Jul 14, 2006
Messages
69
i did try a microsoft browser control, but could not figure out how to have it display the image. When I tried to click on the custom in the design view, it comes back telling me that it is not registered or something.
 

ByteMyzer

AWF VIP
Local time
Yesterday, 20:24
Joined
May 3, 2004
Messages
1,409
Try copying and pasting the following code into your form's Code Module:
Code:
Private Sub Form_Open(Cancel As Integer)

    'Change the URL to the actual URL Path for the image
    Const urlPath As String = "http://www.mysite.com/image.jpg"
    
    Dim byteData() As Byte ' image file data
    Dim urlFile As String  ' parsed image file name
    Dim XMLHTTP As Object  ' HTTP object
    
    ' Parse the image filename from the URL Path
    urlFile = Mid(urlPath, InStrRev(urlPath, "/"))
    
    ' Create the IE HTTP Object
    Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
    
    ' Send the request for the image file
    XMLHTTP.Open "GET", urlPath, False
    XMLHTTP.send
    ' Load the image file data from the response
    byteData = XMLHTTP.responseBody
    
    ' Clear the IE HTTP Object
    Set XMLHTTP = Nothing
    
    ' Write the image file to the Current User's Temp Directory
    Open Environ("Temp") & urlFile For Binary Access Write As #1
        Put #1, , byteData
    Close #1
    
    'Load the image from the Temp file
    Me.[b]Image0[/b].Picture = LoadPicture(Environ("Temp") & urlFile)
    ' [b]--^^^---[/b] change this to the actual image control name
    ' Delete the Temp file
    Kill Environ("Temp") & urlFile

End Sub

See if this works for you.
 

FireStrike

Registered User.
Local time
Yesterday, 23:24
Joined
Jul 14, 2006
Messages
69
Thank you. For anyone else looking for the same thing this will work with only a few changes. first change the that has

urlFile = Mid(urlPath, InStrRev(urlPath, "/") )
to
urlFile = Mid(urlPath, (InStrRev(urlPath, "/") + 1))

without the +1 it will put a "/" on the front of the file. Also since I am not using an activeX control I did not you only need the following line

imaPic.Picture = strFileName

You do not need the load picture function if you are just using an image control.
 

FireStrike

Registered User.
Local time
Yesterday, 23:24
Joined
Jul 14, 2006
Messages
69
oops oh yet the strFileName is actually

strFileName = Environ("Temp") & urlFile

sorry bout that:)

thanks again
 

ByteMyzer

AWF VIP
Local time
Yesterday, 20:24
Joined
May 3, 2004
Messages
1,409
That change should actually be:
from
Code:
urlFile = Mid(urlPath, InStrRev(urlPath, "/") )
to
Code:
urlFile = "\" & Mid(urlPath, InStrRev(urlPath, "/") + 1)
 

Users who are viewing this thread

Top Bottom