【问题标题】:MS Access forms are not showing JPEG pictures with a .jpeg extensionMS Access 表单不显示扩展名为 .jpeg 的 JPEG 图片
【发布时间】:2021-12-29 02:51:34
【问题描述】:

我有一个图像控件,其中控件源设置为数据库图像名称列,它适用于具有 .jpg 文件扩展名的 JPEG 文件,但不适用于具有 .jpeg 扩展名的 JPEG 文件。如果我将 JPEG 文件从 .jpeg 重命名为 .jpg,同时将数据库文件名中的扩展名从 .jpeg 更改为 .jpg,它就像一个魅力。这在生产环境中并不持久,因此如果有人有解决此问题的方法,我将不胜感激。我在 Windows 10 平台上运行 MS Access 2019。

【问题讨论】:

  • 除非您可以使用 OLEObject 控件执行某些操作,否则我认为您会被卡住。代码可以重命名文件并在字段中将jpeg更改为jpg。

标签: windows forms image ms-access jpeg


【解决方案1】:

我的解决方案:每 10 分钟运行一个 bash 文件和一个 crontab 作业。 bash 文件复制、传输和重命名新文件的扩展名。我在我的查询中添加了一个名为“new_bill_Url_location”的列,并剥离了“jpeg”扩展名并添加了一个“jpg”扩展名,带有 jpg 扩展名的文件保持原样。查询列的代码是:

new_bill_Url_location: IIf(Right([bill_Url_location],4)="jpeg", Left(bill_Url_location, Len(bill_Url_location) - 4) & "jpg",[bill_Url_location])

【讨论】:

    【解决方案2】:

    您也许可以使用我的项目VBA.PictureUrl 中演示的简单技术。它会愉快地显示任何普通的位图文件:

    这是核心功能和典型用法(内嵌cmets):

    ' 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
    

    【讨论】:

    • 我真的不明白这对磁盘上但扩展名错误的文件有何帮助。也许为该特定案例添加更多解释?
    • @ErikA:列出的两个顶级文件是相同的。但是,顶部文件已重命名为 .jpeg。它甚至可以是.png,它仍然会显示。
    • @Gustav 谢谢你的代码。我试过你的,但没有成功。
    • 如果您运行 Windows 11,请检查this
    • @Gustav 谢谢你的代码。我试过你的代码没有成功。我一定是误会了什么。但这让我找到了一个解决方案:我每 10 分钟运行一次 bash 和 crontab 作业。 bash 文件复制、传输和重命名新文件的扩展名。我在查询中添加了一个名为 [new_bill_Url_location] 的额外列,并剥离了 jpeg 扩展名并添加了一个 jpg 扩展名,jpg 保持原样。列的代码是:new_bill_Url_location: IIf(Right([bill_Url_location],4)="jpeg", Left(bill_Url_location, Len(bill_Url_location) - 4) & "jpg",[bill_Url_location])
    猜你喜欢
    • 2019-11-05
    • 2013-06-28
    • 2013-08-17
    • 2013-06-17
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 2012-06-30
    相关资源
    最近更新 更多