johnnyg123
asked on
File search/display for all occurrences of Current MDB
There is an access applicatoin that has been changed multiple times and could potentially exist in multiple folders on a given user's pc
I'm trying to write a function that will do a file search on local hard drives for the current mdb name and display the results in a grid.
Not sure of the best way to do this
I'm trying to write a function that will do a file search on local hard drives for the current mdb name and display the results in a grid.
Not sure of the best way to do this
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
peter57r
there is a good chance the user does not have a previous version and thus would save the user from having to do a Windows File Search.
there is a good chance the user does not have a previous version and thus would save the user from having to do a Windows File Search.
ASKER
I created a sample access db named search_files.mdb
I created a form named findfiles that has 2 controls
a list box named lstFileName (unbound, row source type = value list)
a command button named cmdFindFile
I added the following to the form
Private Sub cmdFindFile_Click()
dirTest
Me.lstFileName.RowSource = ""
For i = 1 To dlist.Count
Me.lstFileName.AddItem (dlist(i))
Next i
End Sub
I have a module named search that contains the following:
Option Compare Database
Public dlist As New Collection
Sub dirTest()
Dim startDir As String
Dim i As Integer
Set dlist = Nothing
startDir = "D:\" & CurrentProject.Name
Call FillDir(startDir, dlist)
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
There is a file named search_files.mdb on the root of d: (d:\)
There is a file named search_files.mdb in a folder named access (d:\access)
I was hoping the list box on the form (lstFileName) would contain the following:
d:\search_files.mdb
d:\access\search_files.mdb
(since these are where the 2 files exist)
Instead I'm getting
D:\search_files.mdbsearch_ files.mdb
Not sure what I'm missing
I created a form named findfiles that has 2 controls
a list box named lstFileName (unbound, row source type = value list)
a command button named cmdFindFile
I added the following to the form
Private Sub cmdFindFile_Click()
dirTest
Me.lstFileName.RowSource = ""
For i = 1 To dlist.Count
Me.lstFileName.AddItem (dlist(i))
Next i
End Sub
I have a module named search that contains the following:
Option Compare Database
Public dlist As New Collection
Sub dirTest()
Dim startDir As String
Dim i As Integer
Set dlist = Nothing
startDir = "D:\" & CurrentProject.Name
Call FillDir(startDir, dlist)
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
There is a file named search_files.mdb on the root of d: (d:\)
There is a file named search_files.mdb in a folder named access (d:\access)
I was hoping the list box on the form (lstFileName) would contain the following:
d:\search_files.mdb
d:\access\search_files.mdb
(since these are where the 2 files exist)
Instead I'm getting
D:\search_files.mdbsearch_
Not sure what I'm missing
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok ... you guys have convinced me to do a windows search. (i'll raise the white flag and cry uncle)
Thanks for the posts!
Thanks for the posts!
;-)
use Currentdb.Name to get current access mdb
decent recursive file search code here - adapt to get all listings
http://bytes.com/topic/access/answers/209966-recursive-file-search-vba-vs-vb