Hi all..
Is there a way to assign the source of an image object to a www
location? What I'm looking to do is to have an image object that I can
freely change on a website, that will be loaded each time a user opens
a form.
Specifically, this database is for health intervention data and we are
developing and updating certain guidelines for the intervention as we
go. Ideally I'd be able to upload a new image (containing text of the
guidelines) to a website, and have that image loaded each time the
user clicks opens the "guidelines" - so they would always get the
latest information that had been posted on the website.
Any ideas are appreciated, thanks.
This might work, I have never tried it, but I saved it in my files a long
time ago. In a module, put:
Option Compare Database
Option Explicit
Private Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" ( _
ByVal nBufferLength As Long, _
ByVal lpBuffer As String) _
As Long
Private Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" ( _
ByVal lpszPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFileName As String) _
As Long
Private Const MAX_PATH = 255
Public Function DownloadPicture(ByVal strURL As String) As String
Dim xmlhttp As Object
Dim oStream As Object
Dim strTmp As String
On Error GoTo Err_DownloadPicture
Set xmlhttp = CreateObject("Msxml2.XMLHTTP")
With xmlhttp
.Open "GET", strURL, False
.setRequestHeader "CONTENT-TYPE", "image/jpeg"
.send
Do Until .readyState = 4
DoEvents
Loop
End With
strTmp = GetTmpFileName(Right(strURL, 3))
Set oStream = CreateObject("ADODB.Stream")
With oStream
.Mode = 3 'adModeReadWrite
'.Charset = "iso-8859-1"
.Type = 1 'adTypeBinary
.Open
.Write (xmlhttp.responseBody)
.SaveToFile strTmp
End With
Set oStream = Nothing
Set xmlhttp = Nothing
If Dir(strTmp) <> "" Then
If FileLen(strTmp) > 0 Then
DownloadPicture = strTmp
End If
End If
Exit_DownloadPicture:
Exit Function
Err_DownloadPicture:
MsgBox Err.Description
Resume Exit_DownloadPicture
End Function
Private Function GetTmpFileName(sSuffix As String) As String
Dim strPath As String, _
strFolder As String
Dim lngResult As Long
strFolder = String(MAX_PATH, 0)
lngResult = GetTempPath(MAX_PATH, strFolder)
strFolder = Left$(strFolder, InStr(1, strFolder, Chr$(0)) - 1)
strPath = String(MAX_PATH, 0)
lngResult = GetTempFileName(strFolder, "PIC", 0, strPath)
strPath = Left$(strPath, InStr(1, strPath, Chr$(0)) - 1)
GetTmpFileName = Replace(strPath, ".tmp", "." & sSuffix)
End Function
*****************************************
Then call the function like this:
Me!picfoto.Picture = DownloadPicture(Me!txtURL)
This assumes you have an image object called picfoto, and a textbox called
txtURL that contains the full internet address of the jpg file- it should
include the name and extension: http:/www.mywebsite.com/mypic.jpg
Let me know if it works for you.
Damon
> Hi all..
>
[quoted text clipped - 11 lines]
>
> Any ideas are appreciated, thanks.