Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Show web image in report

Show web image in report

Show web image in report

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 http://www.tek-tips.com/viewthread.cfm?qid=1758167
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 --> Me.Postcode)

Set Image0.Picture = LoadPictureFromURL("https://www.openstreetmap.org/search?query=" & Me.Postcode) 

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

I tried adding a field WebURL _="https://www.openstreetmap.org/search?query=" & Me.Postcode) to the report.
e.g. "https://www.openstreetmap.org/search?query=BS25 5NB"
However I get the same results in both places

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

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

Any ideas?


RE: Show web image in report

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


RE: Show web image in report

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

RE: Show web image in report

> 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.

RE: Show web image in report

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

RE: Show web image in report

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.

RE: Show web image in report

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close