在Access中打开超链接 [英] Open Hyperlinks in Access

查看:722
本文介绍了在Access中打开超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个产品表,其中有一个特定产品用户手册的pdf。我将模型名称及其文件路径存储在我的products表中(在Access中)。我在Access中创建了一个表单,允许用户按产品名称进行搜索,缩小文件数量,并在列表框中显示搜索结果。然而,我最大的问题是打开实际的PDF。它打开文件,但我必须准确存储文件路径,文件的路径很长。有没有办法打开PDF超链接而不使用Followhyperlink命令?或者有一种方法,我只能在列表框中显示pdf的文件名而不是整个路径名?如果我更改了我的产品表中的显示文本,它不会打开超链接,我收到一个错误。任何帮助将不胜感激!

I have a table of products where there is say a pdf for a specific products user manual. I'm storing the model name and it's file path in my products table (in Access). I've created a form in Access that allows the user to search by product name and it narrows down the number of files and shows the results from the search in a list box. However my biggest problem is opening the actual PDF. It opens the file, but I have to store the file path exactly how it is and the path of the files are long. Is there a way to open the PDF hyperlinks without using the Followhyperlink command? Or is there a way that I can show only the file name of the pdf in my list box rather than the entire path name? If I change the display text in my products table it doesn't open the hyperlink, I get an error. Any help would be greatly appreciated!

推荐答案

Application.FollowHyperLink()存在安全性问题,尤其是在网络驱动器上打开文件时。参见例如这里: http://blogannath.blogspot.de/2011 /04/microsoft-access-tips-tricks-opening.html

Application.FollowHyperLink() has problems with security, especially when opening files on a network drive. See e.g. here: http://blogannath.blogspot.de/2011/04/microsoft-access-tips-tricks-opening.html

更好的方法是ShellExecute()API函数。
基本上它看起来像这样(从 http://access.mvps.org修剪) /access/api/api0018.htm ):

A better method is the ShellExecute() API function. Essentially it looks like this (trimmed from http://access.mvps.org/access/api/api0018.htm ):

' This code was originally written by Dev Ashish.
' http://access.mvps.org/access/api/api0018.htm

Private Declare Function apiShellExecute 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

Public Const WIN_NORMAL = 1         'Open Normal
Private Const ERROR_SUCCESS = 32&


Public Function fHandleFile(stFile As String) As Boolean

    Dim lRet As Long

    lRet = apiShellExecute(hWndAccessApp(), "Open", stFile, vbNullString, vbNullString, WIN_NORMAL)

    If lRet > ERROR_SUCCESS Then
        ' OK
        fHandleFile = True
    Else
        Select Case lRet
            ' Handle various errors
        End Select
        fHandleFile = False
    End If

End Function

现在您的列表框:
将其设置为2列,第一列是模型名称,第二列是文件路径。
将第二列的列宽设置为0,因此它将不可见。

Now for your listbox: Set it to 2 columns, the first being the model name, the second the file path. Set the column width of the second column to 0, so it will be invisible.

在doubleclick事件中,使用第二列(文件)调用fHandleFile路径):

And in the doubleclick event, call fHandleFile with the second column (file path):

Private Sub lstManuals_DblClick(Cancel As Integer)

    Call fHandleFile(Me.lstManuals.Column(1))

End Sub

这篇关于在Access中打开超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆