嗨我找不到任何關於此的東西,如果有人能指出我的方向是正確的,那就太好了。Microsoft Access - 根據文件夾目錄+名字自動將圖片鏈接到數據庫
我有4000個健身房成員的訪問數據庫。 我想通過從給定的目錄鏈接來添加個人資料圖片。 我不想手動鏈接4000張圖片
我希望它在目錄中自動搜索和匹配的名字+姓氏+ DOB與圖片中的部件,其具有相同 例如:bobjones05121989
感謝您的幫助。
嗨我找不到任何關於此的東西,如果有人能指出我的方向是正確的,那就太好了。Microsoft Access - 根據文件夾目錄+名字自動將圖片鏈接到數據庫
我有4000個健身房成員的訪問數據庫。 我想通過從給定的目錄鏈接來添加個人資料圖片。 我不想手動鏈接4000張圖片
我希望它在目錄中自動搜索和匹配的名字+姓氏+ DOB與圖片中的部件,其具有相同 例如:bobjones05121989
感謝您的幫助。
一您是否使用Access 2007或更高版本?使用Image控件的ControlSource屬性。的表達可以構造的文件路徑,如:
="C:\somepath\" & [FirstName] & [LastName] & Format([DOB], "ddmmyyyy") & ".jpg"
如果圖像不存在圖像控件將是空白的。
完美謝謝 –
當窗體加載時試試這個。
您需要將字段名稱更改爲數據庫的實際名稱。
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
如果使用Access 2007或更高版本,只需使用構建文件路徑的表達式來設置Image控件的ControlSource屬性即可。不需要VBA。 – June7
您可以修改功能UrlContent從其他一些領域(S)比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
太寬泛的問題,需要額外的信息。你從哪裏得到名字+姓氏+出生地點?我認爲的一種形式?您是否希望將圖片路徑存儲到數據庫中,或者在表單加載後立即顯示它? (如果是這種情況)。請澄清。 –
感謝您的回覆。是的,數據將來自表單。我只是想顯示,例如鏈接。不存儲在數據庫中 –