two questions: 1 - i am using this on my form to populate the lst box showing sub folders, works fine but i need to show only the information after txt in the lstBox and 2- i would like to use this code in creating the report in ms access but report won't accept add function because it is in print mode - is it possible to work around this? many thanks
Code:
Dim Fso As Object 'to hold FSO Dim fmain As Folder 'to hold reference to top level subfolders Dim flevel1 As Folder 'to hold reference to 1st level subfolders Dim flevel2 As Folder 'to hold reference to 2nd level subfolders Dim aFile As File 'to hold reference to Files Dim lst As ListBox Dim txt As TextBox Dim strFileName As String Dim strPath As String Set lst = Me![lstFilesInSubDirectory] Set txt = Me![txtFilePath] Set Fso = CreateObject("Scripting.FileSystemObject") 'Assign the folder to loop Set fmain = Fso.GetFolder(txt) 'Pass your folder path here 'this code loops through the folders,subfolders and files 'this works only upto 2 levels of subfolders For Each flevel1 In fmain.SubFolders For Each aFile In flevel1.files lst.AddItem aFile.Path Next 'loops second level subfolders If flevel1.SubFolders.Count > 0 Then For Each flevel2 In flevel1.SubFolders For Each aFile In flevel2.files lst.AddItem aFile.Path Next Next End If Next Set fmain = Nothing Set flevel1 = Nothing Set flevel2 = Nothing Set aFile = Nothing Set Fso = Nothing End Sub
Comment