944,010 Members | Top Members by Rank

Ad:
Jul 18th, 2005
0

Subfolder Search Loop

Expand Post »
I am very new with VB and am using Access2000 to try to find a Table in ALL mdb's located under Z:\ and look in all mdbs in all folders and subfolders. I need not to see information but to have someone actually help me with this code. There has to be a simple way to do this and keep this code to use a combo box and input into table. This code works well but I have several hundred databases I need to look for and too much to type in for every search. Thanks. :rolleyes:

Can someone help please.

Private Sub Form_Open(Cancel As Integer)
Dim strFile As String
Dim strPath As String

CurrentDb.Execute "DELETE * FROM tblTables"
strPath = "c:\"
strFile = Dir(Z:\ & "*.mdb")

While strFile <> ""
CurrentDb.Execute "INSERT INTO tblTables (TableName, DatabaseName) SELECT Name,'" & strPath & strFile & "' FROM MSysObjects IN '" & strPath & strFile & "' WHERE Name = 'bottling'"

strFile = Dir()
Wend
Me!Combo0.Requery

End Sub
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lcannon is offline Offline
1 posts
since Jul 2005
Jul 19th, 2005
0

Re: Subfolder Search Loop

One solution that I'm fond of, in order to make VB search an entire drive is to shell a dos command of dir and redirect it into a file. Then open the file (which will contain a list of all paths to the files of a specific criteria), read in the paths line for line, and do something accordingly. For example:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. dim wsh
  2. dim PathList() as string
  3. ReDim PathList(0)
  4. set wsh = createobject("WScript.Shell")
  5. wsh.run "dir /a/s/b z:\*.mdb >Z:\tmpfile.dat", 0, 1
  6. open "z:\tmpfile.dat" for input as #1
  7. do until eof(1)
  8. line input #1, tmp
  9. PathList(ubound(PathList())) = tmp
  10. redim preserve PathList(UBound(PathList()) + 1)
  11. loop
  12. close #1
  13. kill "z:\tmpfile.dat"
That should work to load the string array PathList with a list of paths and filenames to MDB files.... if your system doesn't support Scripting (such as the createobject of wscript.shell) then you may need to use API calls (shellexecute) so that you can shell the dir command AND have it wait for the shell to complete before your VB code continues (what a mess it would be, trying to read from a file of paths that isn't done yet huh?). Let me know how it turns out, or if you need further assistance.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: how to get a printer button on a form please
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB Phone Program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC