By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,490 Members | 897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,490 IT Pros & Developers. It's quick & easy.

Recursive File Search VBA vs VB

P: n/a
Hopefully a stupid question, but it doesn't appear that way. Found an
example of a recursive file search, which is exactly what I want, at
Randy Birch's site (mvps.vbnet), but VBA is just different enough not
to compile.

Has anyone successfully adapted this to VBA? Any suggestions?

(Well, short of "go back to your village!")

thanks!

Pieter

Nov 13 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
pi********@hotmail.com wrote:
Hopefully a stupid question, but it doesn't appear that way. Found an
example of a recursive file search, which is exactly what I want, at
Randy Birch's site (mvps.vbnet), but VBA is just different enough not
to compile.

Has anyone successfully adapted this to VBA? Any suggestions?

(Well, short of "go back to your village!")

thanks!

Pieter


There's more than 1 there, which one?

--
[OO=00=OO]
Nov 13 '05 #2

P: n/a
pi********@hotmail.com wrote:
Hopefully a stupid question, but it doesn't appear that way. Found an
example of a recursive file search, which is exactly what I want, at
Randy Birch's site (mvps.vbnet), but VBA is just different enough not
to compile.

Has anyone successfully adapted this to VBA? Any suggestions?

(Well, short of "go back to your village!")

thanks!

Pieter


There's more than 1 there, which one?

--
[OO=00=OO]
Nov 13 '05 #3

P: n/a
You can adopt the following code that I used in ms-access.

Sub dirTest()

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer

startDir = "C:\access\"
Call FillDir(startDir, dlist)

MsgBox "there are " & dlist.Count & " in the dir"

' lets printout the stuff into debug window for a test

For i = 1 To dlist.Count
Debug.Print dlist(i)
Next i

End Sub
Sub FillDir(startDir As String, dlist As Collection)

' build up a list of files, and then
' add add to this list, any additinal
' folders

Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant

strTemp = Dir(startDir)

Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop

' now build a list of additional folders
strTemp = Dir(startDir & "*.", vbDirectory)

Do While strTemp <> ""
If (strTemp <> ".") And (strTemp <> "..") Then
colFolders.Add strTemp
End If
strTemp = Dir
Loop

' now process each folder (recursion)
For Each vFolderName In colFolders
Call FillDir(startDir & vFolderName & "\", dlist)
Next vFolderName

End Sub

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #4

P: n/a
You can adopt the following code that I used in ms-access.

Sub dirTest()

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer

startDir = "C:\access\"
Call FillDir(startDir, dlist)

MsgBox "there are " & dlist.Count & " in the dir"

' lets printout the stuff into debug window for a test

For i = 1 To dlist.Count
Debug.Print dlist(i)
Next i

End Sub
Sub FillDir(startDir As String, dlist As Collection)

' build up a list of files, and then
' add add to this list, any additinal
' folders

Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant

strTemp = Dir(startDir)

Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop

' now build a list of additional folders
strTemp = Dir(startDir & "*.", vbDirectory)

Do While strTemp <> ""
If (strTemp <> ".") And (strTemp <> "..") Then
colFolders.Add strTemp
End If
strTemp = Dir
Loop

' now process each folder (recursion)
For Each vFolderName In colFolders
Call FillDir(startDir & vFolderName & "\", dlist)
Next vFolderName

End Sub

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #5

P: n/a
Which one. Sorry, for some weird reason, I can't get the complete web
page address. but it's "Recursive File Search Demo - Multiple File
Types".

I got it to work. Except for the

List1.Clear

line. Apparently, VB6 and VBA are just ever so slightly different to
make porting the code really annoying. I stripped out all the
references to default properties, like .Text for textboxes and it
worked fine except for the List1.Clear. How to do that - I'm not sure
I'm that worried. Maybe set the thing's rowsource to nothing and
requery it... other than that, it seems to be working. If anyone's
interested, I'll post the code. The changes are basically minor.
Remove all references to default properties, change the rowsource type
of the listbox to Value List and away you go.

Nov 13 '05 #6

P: n/a
Which one. Sorry, for some weird reason, I can't get the complete web
page address. but it's "Recursive File Search Demo - Multiple File
Types".

I got it to work. Except for the

List1.Clear

line. Apparently, VB6 and VBA are just ever so slightly different to
make porting the code really annoying. I stripped out all the
references to default properties, like .Text for textboxes and it
worked fine except for the List1.Clear. How to do that - I'm not sure
I'm that worried. Maybe set the thing's rowsource to nothing and
requery it... other than that, it seems to be working. If anyone's
interested, I'll post the code. The changes are basically minor.
Remove all references to default properties, change the rowsource type
of the listbox to Value List and away you go.

Nov 13 '05 #7

P: n/a
pi********@hotmail.com wrote:
Which one. Sorry, for some weird reason, I can't get the complete web
page address. but it's "Recursive File Search Demo - Multiple File
Types".

I got it to work. Except for the

List1.Clear

line. Apparently, VB6 and VBA are just ever so slightly different to
make porting the code really annoying. I stripped out all the
references to default properties, like .Text for textboxes and it
worked fine except for the List1.Clear. How to do that - I'm not sure
I'm that worried. Maybe set the thing's rowsource to nothing and
requery it... other than that, it seems to be working. If anyone's
interested, I'll post the code. The changes are basically minor.
Remove all references to default properties, change the rowsource type
of the listbox to Value List and away you go.


Yes, List1.Rowsource="", shouldn't need to requery as changing the
rowsource automatically does that.

--
[OO=00=OO]
Nov 13 '05 #8

P: n/a
pi********@hotmail.com wrote:
Which one. Sorry, for some weird reason, I can't get the complete web
page address. but it's "Recursive File Search Demo - Multiple File
Types".

I got it to work. Except for the

List1.Clear

line. Apparently, VB6 and VBA are just ever so slightly different to
make porting the code really annoying. I stripped out all the
references to default properties, like .Text for textboxes and it
worked fine except for the List1.Clear. How to do that - I'm not sure
I'm that worried. Maybe set the thing's rowsource to nothing and
requery it... other than that, it seems to be working. If anyone's
interested, I'll post the code. The changes are basically minor.
Remove all references to default properties, change the rowsource type
of the listbox to Value List and away you go.


Yes, List1.Rowsource="", shouldn't need to requery as changing the
rowsource automatically does that.

--
[OO=00=OO]
Nov 13 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.