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!

ACCESS - Adding image from URL to the report 1

Status
Not open for further replies.

EwaFAMA

Technical User
Oct 24, 2022
7
PL
thread703-1758167

Hi,
I want to use the solution from the another post (suggested by @strongm), but I propably do something wrong in this step:
2) Add an event procedure to the OnFormat event for the report section the control is on

Could you please explain me this step in details?

Thank you in advance for your help.

Ewa
 
Ok, so ..

Step 1. Ensure HasModule is set to true for your report (you'll find thus under the 'Other' tab when viewing the Report's property sheet in design mode)

Now simply left-click the section of the report you are interested in,and have a look at the 'Event' tab in the Property sheet. You'll find an OnClick listed there. Left-Click on that, then click '...', and select 'Code Builder" from the 'Choose Builder' dialog that appears. That'll take you VBA editor in the correct onclick event (for a detail section, for example, this will be "Detail_Click()")
 
strongm, thank you for your prompt reply!

However, it's still not clear for me.
Why earlier you suggested to put the code as OnFormat event and now you are talking about OnClick event?

I've tried in those two ways:
OnClick - nothing happens
OnFormat - there is an error connected with "invalid use of propety" of Image0.Picture

I have everything exactly like in your example (I have object Image0 in section Details)

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Set Image0.Picture = LoadPictureFromURL("[URL unfurl="true"]http://www.blogcdn.com/www.engadget.com/media/2012/03/nokia-n9-inception.jpg")[/URL]
End Sub
 
?as OnFormat event and now you are talking about OnClick

Just me not concentrating. OnFormat is the one to use.

And just to confirm - you are using an MSForms Image control, NOT the Access Image control?

 
Yes, it was my mistake, I used Access Image Control.
Please confirm, if MSForms Image control = ActiveX control/ Microsoft Forms 2.0 Image ?
if yes and I added it correclty to my report, I have another problem now...

Compile error: type mismatch

access_err_xkt2ze.jpg
 
That would suggest that the declaration for CLSIDFromString has somehow got messed up. Since you presumably just copied and pasted it from my working example, this suggest that you might be using 64bit Access. Is this the case? Because if so you'll need to modify the API declarations ...
 
Yes, probably it's a problem with Access version - I use 64bit Access.
Are you able to modify the code for my needs?

I really apraciate your help till now and I am really grateful!
 
Try:

Code:
[COLOR=blue]Public Declare PtrSafe Function CLSIDFromString Lib "ole32.dll" (ByVal lpstrCLSID As LongPtr, ByRef lpCLSID As Any) As Long
Private Declare PtrSafe Function OleLoadPicturePath Lib "oleaut32" (ByVal szURLorPath As LongPtr, ByVal punkCaller As LongPtr, ByVal dwReserved As LongPtr, ByVal clrReserved As OLE_COLOR, ByRef riid As Any, ByRef ppvRet As Any) As LongPtr[/color]
 
Yes, now it works!
Thank you very much for your help!
 
>Do you have any idea why?

Sadly, yes - and I am not sure of a quick or easy workaround.

The answer is in the name of the function: OleLoadPicturePath. It expects to be using a 'path' directly to the image you want to download. But the URL you are having a problem does not do that. It is a REST API query - effectively a function call itself, indirecting the access to the image. And OleLoadPicturePath cannot handle that.

 
I understand and supposed that here is the problem.

So... do you have any other idea how to generate QR code in report in Access?

I have a solution in Excel which use for example this patth " as URL.
Code:
ActiveSheet.Pictures.Insert(URL).Select

Maybe it is possible to implement such solution to Access - it means that some function in a form will generate an image with QR code and raport will take this image from the form.

Or maybe there is a smarter way to generate QR code and I am complicating it ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top