Microsoft Access - 多个项目表单图像

时间:2013-06-18 09:11:46

标签: image ms-access

我有2个表:其中一个名为'ImageDrive',另一个名为'Person'。在Person表中,有一个名为“Primary Image Path”的字段,它存储路径的一部分,即“\ DefaultPicture \ default.jpg”。 ImageDrive表有一个字段Drive,它存储“C:\ MyDocuments \ Pictures”。

我创建了一个Person表单,表单类型为“multiple items form”。然后,我删除了文本框,并将其替换为主图像路径字段的图像控件。

现在的问题是,如何从ImageDrive中的Drive字段中提取信息并将其与Primary Image路径相结合?我需要将它们组合起来以设置图像控制图像。

我尝试过使用Expression Builder,并为图像控制源提供了表达式[ImageDrive]![Drive]&[Primary Image Drive]。但是,当我单击“表单视图”时,它什么也没有显示。

这样做的正确方法是什么?

2 个答案:

答案 0 :(得分:0)

我不确定你是否想在VBA中这样做,但这里有一小段代码可能有助于获得该用户的路径。您可以将其与Recordset组合以引用其他图片表。或者使用两个记录集,每个表一个。

Dim myR as Recordset
Dim myR2 as Recordset
Dim filePath as String

Set myR = CurrentDb.OpenRecordset("ImageDrive", dbOpenDyanset)
Set myR2 = CurrentDB.OpenRecorset("Person", dbOpenDynaset)

'When you open these two Recordsets they will open on the first record of each FYI
'You can either use myR.FindFirst or a Select statment to sort through the records

filePath = myR![Field_name_of_path] & myR2![Field_name_from_other_table]

'Now filePath contains what you need.

'You can also use Environ$("USERPROFILE") & "\My Documents" 
'to get something like C:\username\My Documents and set that as a string as well

Set myR = Nothing
Set myR2 = Nothing

答案 1 :(得分:0)

包含图像控制后,转到图像控件的控制源。并使用dlookup方法获取驱动器,因为表单是使用Person表的字段创建的。下面是要放在控制源上的代码行。

" = DLookUp(" [Drive]"," ImageDrive"," [Drive] IS NOT NULL")& [主要图像路径]"

相关问题