Display an Image using its online URL (1 Viewer)

Diamond-Leopard

Registered User.
Local time
Today, 18:11
Joined
Oct 30, 2018
Messages
26
So I have an inventory of about 10,000 Items and all of the images for these items are online and I have a list of URLS which show the image.

I have a form and when I type in the Item Number I currently have it set to populate lots of text boxes with infomation such as Item Name, Item Cost Etc... I would like to have a picture also Showing the Item...

All I need is a way of displaying The Image from the URL?

Any help would be extremely appreciated

Thank you x
 

isladogs

MVP / VIP
Local time
Today, 18:11
Joined
Jan 14, 2017
Messages
18,219
There are several methods of doing this in a form.
Here are 3 methods that all work. Choose whatever suits your circumstances best:

1) use an ActiveX web browser control
Disadvantage - its ActiveX

2) use LoadPictureFromURL code

Place this in a standard module

Code:
Option Compare Database
Option Explicit

Private Declare Function CLSIDFromString Lib "ole32" (ByVal lpstrCLSID As Long, lpCLSID As Any) As Long
Private Declare Function OleLoadPicturePath Lib "oleaut32" (ByVal szURLorPath As Long, ByVal punkCaller As Long, ByVal dwReserved As Long, ByVal clrReserved As OLE_COLOR, ByRef riid As Any, ByRef ppvRet As Any) As Long

Public Function LoadPictureFromURL(ByVal url As String) As Picture
    Dim IPic(15) As Byte 'holds the IPicture interface
    CLSIDFromString StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"), IPic(0)
    OleLoadPicturePath StrPtr(url), 0&, 0&, 0&, IPic(0), LoadPictureFromURL
    
End Function

Typical Usage:
Code:
LoadPictureFromURL strURL
where strURL is your web page

Disadvantages
a) you need to use an Micrososoft Forms control - again ActiveX
b) API declarations need modifying if you have 64-bit Access

3) use DownloadFileFromWeb code

Place this code in a standard module:
Code:
Option Compare Database
Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
            "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
            szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Public Function DownloadFilefromWeb(url As String, FileName As String) As Boolean
    DownloadFilefromWeb = URLDownloadToFile(0, url, FileName, 0, 0)
End Function

Typical usage:
Code:
DownloadFilefromWeb strURL, strFilePath
where strURL is your web page & strFilePath is where you want to download it to

Disadvantages:
a) You have to download the file to a specified path and view the downloaded file
Doing this method you overwrite the local file each time
b) API declarations need modifying if you have 64-bit Access

I usually use method 3
There may well be other methods
 

Users who are viewing this thread

Top Bottom