嗨,我无法找到任何有关此事的信息,如果有人能指出我正确的方向,那就太好了。
我有一个拥有4000名健身会员的访问数据库。 我想通过链接从给定目录添加个人资料图片。 我不想手动链接4000张图片
我想让它自动搜索目录并匹配成员的名字+姓氏+ DOB与具有相同的图片 例如:bobjones05121989
感谢您的帮助。
答案 0 :(得分:0)
在表单加载时尝试此操作。
您需要将字段名称更改为数据库的实际名称。
Private Sub Form_Load()
Dim imagepath As String
With Me
imagepath = "Drive:\" & LCase(![FirstName]) & LCase(![LastName]) & Format(![DOB], "ddmmyyyy") & ".jpg"
End With
If Len(Dir(imagepath)) > 0 Then
Me.ImageControl.Picture = imagepath
End If
End Sub
答案 1 :(得分:0)
您可以修改 UrlContent 功能以链接ID以外的其他字段,而不是(如此处)下载任何内容(您已经拥有文件)但只返回路径图片:
' Download (picture) file from a URL of a hyperlink field to a
' (temporary) folder, and return the full path to the downloaded file.
'
' This can be used as the control source for a bound picture control.
' If no Folder is specified, the user's IE cache folder is used.
'
' Typical usage in the RecordSource for a form or report where Id is
' the unique ID and Url is the hyperlink field holding the URL to
' the picture file to be displayed:
'
' - to a cached file where parameter Id is not used:
'
' Select *, UrlContent(0, [Url]) As Path From SomeTable;
'
' - or, where Id is used to create the local file name:
'
' Select *, UrlContent([Id], [Url], "d:\somefolder") As Path From SomeTable;
'
' Then, set ControlSource of the bound picture control to: Path
'
' 2017-05-28. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function UrlContent( _
ByVal Id As Long, _
ByVal Url As String, _
Optional ByVal Folder As String) _
As Variant
Const NoError As Long = 0
Const Dot As String = "."
Const BackSlash As String = "\"
Dim Address As String
Dim Ext As String
Dim Path As String
Dim Result As String
' Strip leading and trailing octothorpes from URL string.
Address = HyperlinkPart(Url, acAddress)
' If Address is a zero-length string, Url was not wrapped in octothorpes.
If Address = "" Then
' Use Url as is.
Address = Url
End If
If Folder = "" Then
' Import to IE cache.
Result = DownloadCacheFile(Address)
Else
If Right(Folder, 1) <> BackSlash Then
' Append a backslash.
Folder = Folder & BackSlash
End If
' Retrieve extension of file name.
Ext = StrReverse(Split(StrReverse(Address), Dot)(0))
' Build full path for downloaded file.
Path = Folder & CStr(Id) & Dot & Ext
If DownloadFile(Address, Path) = NoError Then
Result = Path
End If
End If
UrlContent = Result
End Function
可在此处找到文章和完整演示:
Show pictures directly from URLs in Access forms and reports
答案 2 :(得分:0)
您使用的是Access 2007还是更高版本?使用Image控件的ControlSource属性。表达式可以构造文件路径,如:
="C:\somepath\" & [FirstName] & [LastName] & Format([DOB], "ddmmyyyy") & ".jpg"
如果图像不存在,图像控件将为空白。