如何使用存储在数据库字段中的相对路径在ms Access 2013报表中显示图像 [英] How can I display an image in a ms access 2013 report using relative paths stored in a field of a database

查看:176
本文介绍了如何使用存储在数据库字段中的相对路径在ms Access 2013报表中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的数据库,其中的表tblUsers包含以下字段:

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

id-number
名称短文本
姓氏短文本
图片文字

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

在图片"字段中,我为每条记录存储了到链接的图像文件的相对路径(使用表格和用于选择图片的文件对话框). 我目前正在尝试在页面布局上使用9张身份证制作报告,其中使用图像控件通过重新创建文件的完整路径并将其分配给控件的图片来为每条记录显示图片图片属性.

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.

因此,例如:

我有9条记录,其字段Picture的值等于:john_doe1.jpeg到john_doe9,存储为文本. 加载报告时,我希望能够看到9张身份证及其各自的照片. 我尝试使用带有此代码的报告使用on current event

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?

推荐答案

使用绑定的图片控件,即设置其控件来源,例如

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

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

然后,您不需要任何代码.

Then you don't need any code.

GetDBPath()为此必须是公共函数.

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.

这篇关于如何使用存储在数据库字段中的相对路径在ms Access 2013报表中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆