How can I display an image in a ms access 2013 report using relative paths stored in a field of a database

走远了吗. 提交于 2020-06-16 20:51:09

问题


I have a simple database with table tblUsers containing the following fields:

id-number
name-short text
surname-short text
picture-short text

In the picture field I store the relative path to the linked image file for every record (using a form and a file dialog box for selecting picture). I'm currently trying to make a report with 9 id cards on a page layout in which for every record, using an image control, to show the picture for the record by recreating the full path to the file and assingning it to the control's Picture property.

So, as an example:

I have 9 records with the values of the field Picture equal to: john_doe1.jpeg to john_doe9, stored as text. When I load the report, I want to be able to see the 9 id cards with their respective photo atached. I tried using the on current event for the report with this code

Private Sub Report_current()
    Me.txtPathImg = Me.GetDBPath & [tblUsers.picture]
    Me.imgControl.Picture = Me.txtPathImg
End Sub

but all I got is one picture for all the records in the report.

How can I display the correct picture for every record in report view?


回答1:


Use a bound image control, i.e. set it's control source, e.g.

=GetDBPath() & "\" & [picture]

Then you don't need any code.

GetDBPath() must be a public function for this.

Or build the full path in a query, use that query as recordsource, then you can directly bind the image control to the full path.




回答2:


hellow S.Overflow tbl1students:

ID_FullName - dataType : text

Image_Path - dataType : text such as (D:\Imagefolder\FullName.jpg) you know that? ok

............

now create report wizard from tlblstudents table and then open report ac design

ok :

Add Imageframe from toolsbox

then make controlsource :Image_path

..............

you don't need to VBA cods to do that



来源:https://stackoverflow.com/questions/40265600/how-can-i-display-an-image-in-a-ms-access-2013-report-using-relative-paths-store

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