我创建了一个VBA访问应用程序,通过执行一次扫描以获取根文件夹中的所有子文件夹,来在文件夹中查找PDF文件。然后进行另一次扫描,以收集所有文件名并将其与所选文件名进行比较。然后,我们使用以下代码在找到文件时打开该文件:

Private Sub Command132_Click()
On Error GoTo Err_Command132_Click

Dim rootFolder  As String
Dim subFolder   As String
Dim fileSpec    As String
Dim filename    As String
Dim foundfile   As String
Dim filepath    As String
Dim subfolders() As String
Dim co As String
Dim intSubFolderCount As Integer

rootFolder = "T:\Scanned Work Orders (Archives)\"
subFolder = Dir(rootFolder & "*.*", vbDirectory)

'*** Get subfolders in array ***
While subFolder <> ""
    If subFolder <> "." And subFolder <> ".." Then
        ReDim Preserve subfolders(intSubFolderCount)
        subfolders(intSubFolderCount) = subFolder
        intSubFolderCount = intSubFolderCount + 1

        Debug.Print subFolder
    End If
    subFolder = Dir()
Wend

'*** Loop over array and find files ***
    For intSubFolderCount = 0 To UBound(subfolders)
    fileSpec = Trim(Me.Combo_History) & "*.pdf"
    co = subfolders(intSubFolderCount)
    filename = Dir(rootFolder & subfolders(intSubFolderCount) & "\" & fileSpec)
   Do While filename <> ""
        filepath = rootFolder & subfolders(intSubFolderCount)
        foundfile = filepath & "\" & filename
        Application.FollowHyperlink foundfile
        GoTo Exit_Command132_Click
        Exit Do
    Loop

Next intSubFolderCount

MsgBox "No Scanned work order found for " & Me.Combo_History & "!"


Exit_Command132_Click:
   Exit Sub

Err_Command132_Click:

Select Case Err.Number
    Case 52
        MsgBox "No Scanned work order found for " & Me.Combo_History & "!"
    Case Else
        MsgBox Err.Number & "-" & Err.Description
  End Select
End Sub

但是在我办公室的某些计算机上,他们收到此错误消息:

“某些文件可能包含病毒或对计算机有害。
确保此文件来自可信赖的来源非常重要。

您要打开该文件吗?”

有可能抑制这种情况吗?我们正在运行Windows 7专业版。

最佳答案

这是Windows功能。 Microsoft在此处删除了KB。
https://support.microsoft.com/en-us/kb/925757

可以使用VBA更改注册表设置,但首先请按照KB的说明进行操作,以确保它可以解决您的问题。

关于ms-access - 如何防止出现此错误信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31841128/

10-12 00:42