[英]How do I display an MS Access Table Attachment or an image stored in a SharePoint location on a form?
我正在為一個使用 Microsoft Access for Office 365 的工作項目制作一個小游戲。我有一個表格,其中包含所有答案和作為附件存儲的相關圖片。 用戶將通過 SQL 查詢滾動通過記錄源提供的記錄。
我想在用戶導航時顯示與每條記錄相關的圖像。
我更願意將圖像存儲在其他地方,但並非所有預期用戶都可以訪問公共網絡文件夾。 我確實可以訪問常見的 SharePoint 位置,我可以在其中將結果上傳到鏈接的 SharePoint 列表中,但是當我嘗試從 SharePoint 位置插入圖像時,MS Access 不允許“網址”。
在測試中,我使用 VBA 通過子窗體上的圖片屬性將圖像(托管在網絡文件夾上)顯示為背景,但由於並非所有用戶都可以訪問公共網絡文件夾,因此我無法執行此操作在生產中。 (創建后發現沒有通用文件夾。)
如何在附件中顯示該圖片?
或者
如何使用 SharePoint 托管圖像?
使用“開箱即用”的 MS Access 是否可以實現這些功能?
編輯:使用 .accdr 格式防止用戶查看表格中的答案
由於您將擁有圖片的 URL,您可以使用我的奇特函數UrlContent :
' 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
可以在我的項目VBA.PictureUrl 中找到完整的代碼、文檔和演示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.