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
httpGet "http://i2.microsoft.com/h/all/i/ms_masthead_8x6a_ltr.jpg", _
"C:\ms_masthead_8x6a_ltr.jpg"
It works perfectly, many thanks.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.
That's exactly what I'm already doing but it doesn't seem to refresh the image and still loads the old version from somewhere.you requery your Image control by Setting again the Picture property to the Local path and filename of the image file.
'Get the URL of where the image would be if it's saved
Dim str_url As String
str_url = "https://www.MYURL.COM/catalogue/" & Me.cbo_product_code & ".jpg"
'Check if the file exists
If CheckNetFile(str_url) = True Then
'If it does exist on the online server then save a local copy
httpGet "https://www.MYURL.COM/catalogue/" & Me.cbo_product_code & ".jpg", "C:\DEAN\Catalogue\" & Me.cbo_product_code & ".jpg"
'Then load the downloaded local copy
Me.img_product.Picture = "C:\DEAN\Catalogue\" & Me.cbo_product_code & ".jpg"
Else
'Display no image available
Me.img_product.Picture = "C:\DEAN\Catalogue\no_image_available.jpg"
End If
'Delete the local file first
'Kill "C:\DEAN\Catalogue\" & Me.cbo_product_code & ".jpg"
I imagine this could suffer from the same problem; but since I am currently not in front of a computer, would you mind testing it for me?There is a new version, I'm uploading one speficially to test for this issue as my users are reporting it. My tests are all failing. Going directly to the URL shows the new version. Going directly to the locally-saved version shows the old version.
Hmm, I don't have a mdb to try, so I'm not sure about that.It's not there a under the list of controls in form design. I'm using Access 365 but my DB is an MDB - is this limiting my options?