We help IT Professionals succeed at work.
Get Started

Alternative for Application.Filesearch in Office 2010 - VBA

1 Endorsement
Last Modified: 2012-08-14
I am pasting a code block below.. Which uses some iteration withing Application.Filesearch. Could anyone edit the code for me to make it work in 2010. I hope Application.Filesearch does not work in office 2010. It would be helpful to know some comments on the code.
Private Sub FichImporte_GotFocus()
Dim CSql As String
Dim rst As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim intLenRep As Integer
Dim intLen As Integer

Set cnn = CurrentProject.Connection

intLenRep = Len(stRepCh)


    Set rst = New ADODB.Recordset
    Set rs1 = New ADODB.Recordset

    'Active la connection de la base Access
    Set rst.ActiveConnection = cnn

    'Ouvre le recordset qui correspond à la table ci-dessous.
    rst.Open CSql, , adOpenKeyset, adLockOptimistic

    With Application.FileSearch
        'Débute une nouvelle recherche
        'Définit les critères de recherche
        .LookIn = stRepCh
        .FileName = "*.*"
        .SearchSubFolders = True
    End With

With Application.FileSearch
    'Exécute la recherche
        If .Execute() > 0 Then
            For i = 1 To .FoundFiles.Count
                'TextBox.Value = .FoundFiles(i)
                intLen = Len(.FoundFiles(i))
                stFichier = Right(.FoundFiles(i), intLen - intLenRep)
                'Call ShowFileInfo(.FoundFiles(i))
                With rst
                    If Right(stFichier, 11) <> "_traite.xls" Then
                            .Fields(1) = stFichier
                            '.Fields(2) = s
                    End If
                End With
            Next i
        End If
End With

End Sub

Open in new window

Watch Question
Top Expert 2011
This problem has been solved!
Unlock 2 Answers and 18 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE