MS Access按钮打开服务器上的PDF。

huangapple go评论51阅读模式
英文:

MS Access button to open a PDF on a server

问题

我们正在尝试创建一个交付证明数据库,并希望在表单上添加一个按钮,该按钮可以打开服务器上扫描的PDF文件。

在表格中,我们已经创建了一个计算字段的表达式 [Location] & [Invoice No] & [PDF],它显示文件的位置(Z:\Carriers\POD\123.pdf)。

是否有一种方法可以在表单中创建一个按钮,以查看 [文件位置] 字段并打开PDF文件?

英文:

We are trying to create a proof of delivery database and would like a button on a form that would open a scanned pdf on our server.

In the table we have created a expression in a calculated field [Location] & [Invoice No] & [PDF] which displays the location of the file (Z:\Carriers\POD\123.pdf)

Is there a way to create a button in a form that will look at [File Location] field and open the pdf

答案1

得分: 1

感谢您的建议,无法使它们起作用。

找到了关于FollowHyperlink的信息并使用了这个代码:

Application.FollowHyperlink "Z:\Carriers\POD" & Me.[Invoice] & ".pdf"

正好满足了我们的需求。

再次感谢大家的时间。

英文:

Thanks for your suggestions, could not get them to work.

Found info about FollowHyperlink and used this

Application.FollowHyperlink "Z:\Carriers\POD" & Me.[Invoice] & ".pdf"

Does exactly what we need

Thanks everyone again for your time

答案2

得分: 0

你可以使用这个函数,它将打开任何 Windows 可以显示的文件:

Option Compare Database
Option Explicit

' 用于 OpenDocumentFile 的 API 声明。
' 文档:
'   https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea
'
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hWnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long

Private Declare PtrSafe Function GetDesktopWindow Lib "USER32" () _
    As Long
    
' ShowWindow 常量的枚举(选择)。
' 文档:
'   https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
'
Public Enum SwShowCommand
    swShowNormal = 1
    swShowMinimized = 2
    swShowMaximized = 3
End Enum
   
' 使用默认的查看器应用程序打开文档文件。
' 可选地,可以以最小化或最大化方式打开文档。
'
' 如果成功返回 True,否则返回 False。
' 如果路径或文件未找到,不会引发错误。
'
' 2022-03-12。Gustav Brock,Cactus Data ApS,CPH。
'
Public Function OpenDocumentFile( _
    ByVal File As String, _
    Optional ByVal ShowCommand As SwShowCommand = swShowNormal) _
    As Boolean

    Const OperationOpen     As String = "open"
    Const MinimumSuccess    As Long = 32
    ' 打开文档不应该有一个值。
    Const Parameters        As String = ""
    
    Dim Handle      As Long
    Dim Directory   As String
    Dim Instance    As Long
    Dim Success     As Boolean
    
    Handle = GetDesktopWindow
    Directory = Environ("Temp")

    Instance = ShellExecute(Handle, OperationOpen, File, Parameters, Directory, ShowCommand)
    ' 如果函数成功,它将返回大于 MinimumSuccess 的值。
    Success = (Instance > MinimumSuccess)
    
    OpenDocumentFile = Success

End Function

注意:这是 Visual Basic for Applications (VBA) 代码,用于在 Windows 上打开文件的功能。

英文:

You can use this function which will open any file, that Windows can display:

Option Compare Database
Option Explicit

' API declarations for OpenDocumentFile.
' Documentation:
'   https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea
'
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hWnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long

Private Declare PtrSafe Function GetDesktopWindow Lib "USER32" () _
    As Long
    
' Enum for ShowWindow constants (selection).
' Documentation:
'   https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
'
Public Enum SwShowCommand
    swShowNormal = 1
    swShowMinimized = 2
    swShowMaximized = 3
End Enum
   
' Open a document file using its default viewer application.
' Optionally, the document can be opened minimised or maximised.
'
' Returns True if success, False if not.
' Will not raise an error if the path or file is not found.
'
' 2022-03-12. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function OpenDocumentFile( _
    ByVal File As String, _
    Optional ByVal ShowCommand As SwShowCommand = swShowNormal) _
    As Boolean

    Const OperationOpen     As String = "open"
    Const MinimumSuccess    As Long = 32
    ' Shall not have a value for opening a document.
    Const Parameters        As String = ""
    
    Dim Handle      As Long
    Dim Directory   As String
    Dim Instance    As Long
    Dim Success     As Boolean
    
    Handle = GetDesktopWindow
    Directory = Environ("Temp")

    Instance = ShellExecute(Handle, OperationOpen, File, Parameters, Directory, ShowCommand)
    ' If the function succeeds, it returns a value greater than MinimumSuccess.
    Success = (Instance > MinimumSuccess)
    
    OpenDocumentFile = Success

End Function

huangapple
  • 本文由 发表于 2023年3月8日 19:20:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75672350.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定