[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 831
  • Last Modified:

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



0
emilysam
Asked:
emilysam
  • 2
1 Solution
 
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
 
emilysamAuthor Commented:
Well Done!!!  Thanks!
0
 
emilysamAuthor Commented:
Thanks for the quick help!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now