PDA

Click to See Complete Forum and Search --> : Searching in folders


Jan 4th, 2000, 05:28 PM
How do you search within a folder for specific files? I've got browse functionality included to get to the folder I want.

Cheers

venkatraman_r
Jan 4th, 2000, 06:23 PM
Add this module, add a drive list box and a command button....

Private Sub FindIt(sStartPath As String, sPattern As String)
On Error GoTo VenError:
Dim fso As FileSystemObject
Dim fld As Folder
Dim fldCurrent As Folder
Dim sFile As String

Screen.MousePointer = vbHourglass

Set fso = New FileSystemObject
If Right$(sStartPath, 1) <> "\" Then
sStartPath = sStartPath & "\"
End If

Set fldCurrent = fso.GetFolder(sStartPath)
sFile = Dir(sStartPath & sPattern, vbNormal)

Do While Len(sFile) > 0
List1.AddItem sStartPath & sFile
sFile = Dir
Loop
end sub

in the command button:

Call FindIt(Drive1.Drive & "\", "*.mdb")

Where u can specify the file type u need instead of "mdb".

Hope this helps,

Venkat.

Jan 4th, 2000, 10:49 PM
Venkat

Thanks for the code but I can't get it to work. An error came up with the call FindIt to say that it isn't defined, so I made in public, now I've got an error with the FileSystemObject and Folder saying that the user types aren't defined. What should I do.

V

Aaron Young
Jan 5th, 2000, 11:42 AM
Venkatraman is using the File System Objects which requires the MS Scripting Runtime File(s).
Goto Project.. References and put a Check in MS Scripting Runtime and it should recognize them.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

Jan 5th, 2000, 11:55 AM
Thank You........Again!