Creating a report that will display a number of images from filenames in a table

人盡茶涼 提交于 2019-11-28 10:22:07

问题


I have a VBScript that I use to read an XML file and populate a couple of tables in Access 2010. The VBScript also copies jpg files from a card reader to a location on the server. The VBScript creates a unique folder based on date/time...the folder location of each image name is written to the database as one of the fields in UNC path\filename.jpg notation.

I have a primary database and the transaction (images) are referenced in the second database. I have created a relationship as well... I am able to build my report in Access from data from both the tables, however, I'd like to automate a print job that grabs the last entry to the primary database, it's associated images (up to 10...but not 10 in every case) and print them out. When I try to build the report I cannot figure out how to use a query result of the field with the filenames to display on the report.


回答1:


You can do what you describe using an Image control and a line of VBA code. For a sample table named [ImageLocations]

ImageLocation                           
-----------------------------------
\\SERVER\Public\Pictures\image1.jpg        
\\SERVER\Public\Pictures\image2.jpg

I created a report with that table as the Record Source, dropped the [ImageLocation] field onto the Detail band, and added an Image control. I used the following as the On Format event of the report's Detail section:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Me.ImageControl.Picture = Me.ImageLocation.Value
End Sub

When I print the report I see the images associated with the filenames in the table.

Edit re: comment

Newer versions of Access (since at least Access 2010) do not need the On Format VBA code. We can simply place an Image control on the report and set its Control Source property to the (text) field containing the path to the image file. Thanks to Albert D. Kallal for the tip!



来源:https://stackoverflow.com/questions/20892445/creating-a-report-that-will-display-a-number-of-images-from-filenames-in-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!