| | |
Subfolder Search Loop
![]() |
•
•
Join Date: Jul 2005
Posts: 1
Reputation:
Solved Threads: 0
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
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
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:
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
dim wsh dim PathList() as string ReDim PathList(0) set wsh = createobject("WScript.Shell") wsh.run "dir /a/s/b z:\*.mdb >Z:\tmpfile.dat", 0, 1 open "z:\tmpfile.dat" for input as #1 do until eof(1) line input #1, tmp PathList(ubound(PathList())) = tmp redim preserve PathList(UBound(PathList()) + 1) loop close #1 kill "z:\tmpfile.dat"
![]() |
Similar Threads
- finding max value of 10 integers (C++)
- MSFlexGrid Search Loop (Visual Basic 4 / 5 / 6)
- Extracting Numbers (C)
- Allocating Memory (C++)
- Help with Java programming for lottery (Java)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: how to get a printer button on a form please
- Next Thread: VB Phone Program
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






