通过单击Microsoft Access表单中的链接从网络驱动器打开文件驱动器、表单、单击、链接

2023-09-03 09:36:02 作者:牽手い約定今生

我使用以下代码打开文件位置文件夹,但是我想打开文件本身而不是文件夹位置。

有人能建议我更改代码中的哪些内容吗?

Private Sub File_locationButton_Click()

    Dim filePath
    filePath = File_Location 

    Shell "C:WINDOWSexplorer.exe """ & filePath & "", vbNormalFocus

End Sub

推荐答案

Access2013两个数据表建立关系的具体操作

可以使用ShellExecute,所以:

Private Sub File_locationButton_Click()

    Dim filePath
    filePath = File_Location 

    OpenDocumentFile filePath

End Sub

哪些调用:

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
    
' ShowWindow constants (selection).
' Documentation:
'   https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
'
Private Const SwShowNormal      As Long = 1
Private Const SwShowMinimized   As Long = 2
Private Const SwShowMaximized   As Long = 3

    
' 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-02. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function OpenDocumentFile( _
    ByVal File As String, _
    Optional ShowCommand As Long = 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
 
精彩推荐