Using Application.FileSearch and Application.FollowHyperlink... how can it open two or more files in same folder with same keyword in filename

Hi Experts,
Using the following code to link from a MS Access form to the related file in a network folder and open it.  The code works great for it successfully opens the correct folder based upon the keyword (which is a textbox on the form).  The issue I have which is probably unique only to this project is that some records in Access form relate to 2 files in the network folder not just one.  Currently the code opens only one file yet I would like the command to open both files upon the button click.  Thanks!

The code is based upon a snippet from this experts-exchange question:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_21210119.html?sfQueryTermInfo=1+locatefil


Private Sub Command2_Click()
DoCmd.Hourglass True
 Dim strFileName As String
 strFileName = Me.txtDocID2
 
         Dim vItem As Integer, strPath As String
         With Application.FileSearch
            .filename = strFileName
            .LookIn = "\\server\ProjectTest\"
            .SearchSubFolders = True
         If .Execute > 0 Then
            For vItem = 1 To .FoundFiles.Count
            strPath = .FoundFiles(vItem)
               Debug.Print strPath
            Next vItem
            Else
                MsgBox "File not found"
                     
         End If
        End With
DoCmd.Hourglass False
Application.FollowHyperlink strPath, False, True

End Sub



emilysamAsked:
Who is Participating?
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
Private Sub Command2_Click()
DoCmd.Hourglass True
 Dim strFileName As String
 strFileName = Me.txtDocID2
 
         Dim vItem As Integer, strPath As String
         With Application.FileSearch
            .filename = strFileName
            .LookIn = "\\server\ProjectTest\"
            .SearchSubFolders = True
         If .Execute > 0 Then
            For vItem = 1 To .FoundFiles.Count
            strPath = .FoundFiles(vItem)

            Application.FollowHyperlink strPath, False, True  '<< MOVED here
               Debug.Print strPath
            Next vItem
            Else
                MsgBox "File not found"
                     
         End If
        End With
DoCmd.Hourglass False
'  Application.FollowHyperlink strPath, False, True  '<< Moved UP

End Sub

* note: will open all the files found
0
 
emilysamAuthor Commented:
Well Done!!!  Thanks!
0
 
emilysamAuthor Commented:
Thanks for the quick help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.