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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
emilysamAuthor Commented:
Well Done!!!  Thanks!
0
emilysamAuthor Commented:
Thanks for the quick help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.