Executing Code Behind a Report

richlocus
2StarLounger
Posts: 154
Joined: 03 Oct 2015, 00:30

Executing Code Behind a Report

Post by richlocus »

Hello:

I have been researching how to put images in a report that vary with each row depending on the object being displayed. For example, I have an Access report that creates a row for each product, with a picture in an Image Frame along with the product details.

My question is how to link the image frame to the code that will pull up the image.

Images are kept on a server in JPG format.

Attached please find the report layout. Please note that I have looked at all the events for the report and I don't see any that reference code that will be executed when each new report is created in the report.

I attached the code that would populate the Image Frame, along with the code I would use to actually populate it. But I don't see where the code to populate the image frame links to the report layout. I need to pass the code the name of the style and where the image is stored in jpg format for each new row.

Can you tell me how the image frame is refreshed with a new image for each row? I don't see where it is activated for each new report row.

I use a tool called AccDevTools and it shows the code to refresh the image is already in the application, but I don't see the linkage to the report.

I have spent half a day trying to figure this out.

Thanks!
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78417
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Executing Code Behind a Report

Post by HansV »

I suspect that the function DisplayImage is called in the On Format (or perhaps On Print) event of the Detail section of the report.

However, all modern versions of Access have a much easier way of displaying variable images on a form or report.
- Store the full path and filename of the images in a text field in the table behind the form report.
- Set the Control Source of the image control to the name of the text field.

If you'd rather keep the path and filename separate:
- Store just the filename in a text field in the table.
- Create a query based on the table and create a calculated column that concatenates the path and filename.
- Use this query as Record Source for the form or report.
- Set the Control Source of the image control to the name of the calculated column.
Best wishes,
Hans

richlocus
2StarLounger
Posts: 154
Joined: 03 Oct 2015, 00:30

Re: Executing Code Behind a Report

Post by richlocus »

Hans:
You got it! It was in the Detail section, On Print event. The form was packed so tight (I didn't create it) that I never clicked a blank space in the detail section. Thanks you!
Rich

User avatar
HansV
Administrator
Posts: 78417
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Executing Code Behind a Report

Post by HansV »

Tip: you can also click the header of the Detail section to select it.
Best wishes,
Hans