Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show web image in report

Status
Not open for further replies.

ridders52

Programmer
Aug 7, 2017
16
0
0
GB
I'm trying to include an online map for a UK postcode in an Access report.

I'd already tried using a web browser control exactly as I'd used in a form.
It doesn't work

Then I found this old thread via a Google search [URL unfurl="true"]http://www.tek-tips.com/viewthread.cfm?qid=1758167[/url]
The solution by strongm using a standard image control looked like EXACTLY what I needed.

However I get an 'invalid use of property' error on this line when its in the Detail_Format event:
Code:
https://www.openstreetmap.org/search?query="[/URL] & Me.Postcode)]Set Image0.Picture = LoadPictureFromURL("[URL unfurl="true"]https://www.openstreetmap.org/search?query="[/URL] & Me.Postcode)

I moved it to the Report_Load event - no error but the control is empty

I tried adding a field WebURL _=" & Me.Postcode) to the report.
e.g. " 5NB"
However I get the same results in both places

Capture_airopq.png


I also tried hard coding a web image - the one in strongm's post.
"Exactly the same result so its nothing to do with the space in the postcode

EDIT:
Just compiled and it barfs at the Set Image0.Picture line in the Report_Load section

Any ideas?

Colin
 
Forum703

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Oops
Thanks for the link to the VERY recent thread!
Exactly the same issue as me

Apologies for not doing a forum search first

I know I've followed strongm's instructions exactly
I'm using Access 2010 32-bit though I doubt that's relevant

Colin
 
I have done some more research in this topic and found some alternative code:

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

This allowed me to include various image from web sites in my reports without error.
However, it also failed when I tried to use it to create a 'static' map from online map providers (Open Street Map / Bing / Google / Michelin)

Fortunately there was a much easier solution.
The Google Maps API is free to use and this allows you to download 'static' maps.
It is very simple to use.
See this link for detailed instructions & to get an API key: Google Maps for developers

Report_iylvmx.png


 
 http://files.engineering.com/getfile.aspx?folder=c2c57913-c285-43d4-bce3-805955f8fa45&file=Report.PNG
> found some alternative code:

But that's not alternative code. That's exactly the same as my code, even down to the comment, from the thread you referenced in your first post.

>it also failed when I tried to use it to create a 'static' map from online map providers

Well, it would fail. As I said before, this code is for downloading an image. It is not a screen scraper. It doesn't turn a web page into a bitmap and download that. It expects to find an image as the target of the URL. Which is of course exactly what the Google Static Maps API actually provides: a URL to an image.

Having said that - there is one bit of critical info missing in my original code: the Image control needs to be the MS Forms ActiveX image control, not the Access image control.
 
Apologies to @strongm.

It was late & I copied / pasted your code as you correctly pointed out.
Just to make things worse, I tried to be 'helpful' by also pasting in the other thread

OK - the alternative code I found (can't remember where or the author) is as follows:

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

That does work correctly with a standard Access image control on standard web images such as the link in strongm's post.
I used that code to download the 'static' map image defined using Google Maps API

I've also re-tested strongm's code using the ActiveX MS Forms image control & his example image & it works perfectly
 
You probably need to point out that this alternative works through an intermediate step (i.e. it downloads the image to local storage, and you need to pass that filename to the Access control. Perfectly legit solution.
 
Yes the file is downloaded to the local computer and then loaded into the report or form.
However for the static Google maps I am using, it is instantaneous.
I also overwrite the same map.BMP file each time I change the postcode to avoid wasting disk space.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top