| Platform: | Microsoft Access |
| Task: | Loop through files in a directory |
| Discussion: | You need to loop through the files in a directory. This example loads the files into a ListBox. |
| Example: | Private Sub LoadSurveyFilesIntoListBox()
On Error GoTo Error
'clear the listbox
For i = 0 To Me.SurveyFilesListBox.ListCount - 1
Me.SurveyFilesListBox.RemoveItem i
i = i - 1
Next i
'loop through the files in the directory
FilesList = Dir(CurrentSurveyDirectory & "\*.*", vbNormal)
Do Until LenB(FilesList) = 0
Me.SurveyFilesListBox.AddItem FilesList
FilesList = Dir$
Loop
Exit Sub
Error:
Debug.Print Err.Description
End Sub |