I have files in the C:\database.. I would like to populate the files in this folder into my combo box? How to start this?
Printable View
I have files in the C:\database.. I would like to populate the files in this folder into my combo box? How to start this?
Where I have to put the directory name "C:\Database" in your code.
I have simplified the above code for you :)
vb Code:
'Add a reference to 'Microsoft Scripting Runtime' Sub Searchforfiles() Dim Fso As Object, fmain As Folder, aFile As File Set Fso = CreateObject("Scripting.FileSystemObject") 'Pass your folder path here Set fmain = Fso.GetFolder("C:\Database") For Each aFile In fmain.Files MsgBox aFile.Name 'Code to add to combobox Next Set fmain = Nothing Set aFile = Nothing Set Fso = Nothing End Sub
Thank you so much.. I would like to search a specific files with the extension *.shp.. How to do that?
vb Code:
'Add a reference to 'Microsoft Scripting Runtime' Sub Searchforfiles() Dim Fso As Object, fmain As Folder, aFile As File Set Fso = CreateObject("Scripting.FileSystemObject") 'Pass your folder path here Set fmain = Fso.GetFolder("C:\Database") For Each aFile In fmain.Files If Right(aFile.Name, 4) = ".shp" Then 'Code to add to combobox End If Next Set fmain = Nothing Set aFile = Nothing Set Fso = Nothing End Sub
And without the FSOCode:Private Sub Command1_Click()
Dim strLoad As String
Combo1.Clear
strLoad = Dir("c:\Database\*.*")
Do While strLoad > vbNullString
Combo1.AddItem strLoad
strLoad = Dir
Loop
End Sub
If all you want are those, then why load all filesQuote:
Originally Posted by matrik02
Code:Private Sub Command1_Click()
Dim strLoad As String
Combo1.Clear
strLoad = Dir("c:\Database\*.shp")
Do While strLoad > vbNullString
Combo1.AddItem strLoad
strLoad = Dir
Loop
End Sub