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!

Printing a web image in a report

Status
Not open for further replies.

CJRhoads

Instructor
Aug 8, 2017
2
0
0
US
I am trying to follow the directions from strongm in the previous closed thread:

thread703-1758167

It doesn't appear to be working for me, probably because there is something I don't understand. I'm a power user, not really a programmer. After setting the format event on the group header section, and creating and saving the function in the module, nothing appears in the report. I suspect it may be related to my not knowing how to switch from the example URL to the field URL. The original that strongm posted was:
Set Image0.Picture = LoadPictureFromURL(" SOurce file - this text could obviously come from a field in a table, for example
I have tried two ways to use the URL from the field in the table. The first won't run at all and gives me a picture1web not found error.
Set Image0.Picture = LoadPictureFromURL([picture1web])

The second will let me see the report, but the picture doesn't appear and if I try to preview or print the report I get an error that says a custom macros has failed to run preventing the report from rendering.
Set Image0.Picture = LoadPictureFromURL("[picture1web]")

The problem might also be that I did the module wrong. I've never added a module to a database before other than to add events to forms. Can anyone help shed some light on this issue?

If not, does anyone have any ideas for me? I just want to print a program guide of workshop leaders names, bios, picture, and workshop descriptions in a book. All of the pictures of the people have been loaded into an Access 2013 database. I can view a form on the screen with the pictures in it, but it won't print. I haven't been able to get the report to show the pictures either (insofar that the web browser object is not supported in reports). I've tried doing a Word Merge, but it just posts the URL and not the picture. If I could figure out how to do it in HTML I would try that, but as I noted, I'm not a real programmer.

Any help would be greatly appreciated.

Peace
CJ Rhoads
 
You probably need to confirm the exact contents of [picture1web] that fails, and let us know what it is.
 
I had exactly the same problem with the supplied code.

I found this alternative code which worked perfectly for many online images

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

Unfortunatley it was no use for the 'static' online maps I wanted but I used Google Maps API instead & it worked perfectly
See this thread: Show Web Image in Report
 
Thanks, ridders52. I'll try it and let you know.

Also, strongm, the contents of pictureweb1 was on my own website: for example. The URL works fine in the form, so I'm sure there is nothing wrong with the URL. It is a hyperlink type, although I have the text itself stored in another field I called pictureweb1text, but that didn't work either.

Thanks
CJ Rhoads
 
>I found this alternative code

As I pointed out in the other thread, it is the exact same code. My code. Not an alternative. The same.

By the way, the URL you have provided currently does not point to an image file, it goes to 1 404 page. At least it does when I feed it into Edge or IE. So, again, my code - designed to download a image - won't work. So I'll assume that you tested the URL when there was an image there. But my point was really to gently prod you to see whether you really meant

Set Image0.Picture = LoadPictureFromURL("[picture1web]")

which is not passing the contents of the field as the URL, it is passing the fieldname itself (as the error message you were getting was trying to tell you)

However, as I pointed out to ridders52 in his thread, there is a bit of critical info missing in my code - the Image control needs to be the MS Forms ActiveX image control, not the Access image control since the Access control does not directly expose any of the OLE Picture interfaces

 
Apologies to @strongm.

Below is a copy of my own reply from my own thread (hopefully I can at least get that right!) [bigsmile]
======================================================================
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
 
Yep, perfectly reasonable alternative, with the caveat that it requires an intermediary step (saving the file locally before it can be loaded into the control)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top