jdlsmith
asked on
FileSearch in 2002 runtime
Situation:
Program developed in Access 2000.
Uses FileSearch:
*****************
Private Sub RefreshList()
Dim fs
Dim strDirectory As String
Dim strFiles As String, strFile As String
If IsNull(Me.cbDirectory) Then
DefaultDir
End If
strDirectory = Me.cbDirectory
Set fs = Application.FileSearch
fs.NewSearch
fs.LookIn = strDirectory
fs.FileName = "*.dmc"
If fs.Execute(SortBy:=msoSort byFileName , SortOrder:=msoSortOrderAsc ending) > 0 Then
'MsgBox "There were " & fs.FoundFiles.Count & " file(s) found."
For i = 1 To fs.FoundFiles.Count
'MsgBox fs.FoundFiles(i)
strFile = Left(Right(fs.FoundFiles(i ), Len(fs.FoundFiles(i)) - Len(strDirectory)), Len(fs.FoundFiles(i)) - Len(strDirectory) - 4)
If strFiles <> "" Then
strFiles = strFiles & ";" & strFile
Else
strFiles = strFile
End If
Next i
Else
MsgBox "There were no files found."
End If
Me.lstFiles.RowSource = strFiles
Me.lstFiles.Value = Null
End Sub
**************************
Works in a runtime 2000 version.
Upgraded to 2002.
FileSearch no longer works in runtime, though it works as an mdb.
All references appear to be there (though for version 10 instead of 9.0.
Is the way I use FileSearch no longer quite right? Does something need to be added or removed? Is there another way to achieve the same thing?
Thanks,
JS
Program developed in Access 2000.
Uses FileSearch:
*****************
Private Sub RefreshList()
Dim fs
Dim strDirectory As String
Dim strFiles As String, strFile As String
If IsNull(Me.cbDirectory) Then
DefaultDir
End If
strDirectory = Me.cbDirectory
Set fs = Application.FileSearch
fs.NewSearch
fs.LookIn = strDirectory
fs.FileName = "*.dmc"
If fs.Execute(SortBy:=msoSort
'MsgBox "There were " & fs.FoundFiles.Count & " file(s) found."
For i = 1 To fs.FoundFiles.Count
'MsgBox fs.FoundFiles(i)
strFile = Left(Right(fs.FoundFiles(i
If strFiles <> "" Then
strFiles = strFiles & ";" & strFile
Else
strFiles = strFile
End If
Next i
Else
MsgBox "There were no files found."
End If
Me.lstFiles.RowSource = strFiles
Me.lstFiles.Value = Null
End Sub
**************************
Works in a runtime 2000 version.
Upgraded to 2002.
FileSearch no longer works in runtime, though it works as an mdb.
All references appear to be there (though for version 10 instead of 9.0.
Is the way I use FileSearch no longer quite right? Does something need to be added or removed? Is there another way to achieve the same thing?
Thanks,
JS
I changed in A2002 fileformat your sub into a function in a like:
Function RefreshList(strDirectory As String)
Dim fs
Dim strDirectory As String
Dim strFiles As String, strFile As String
Dim i As Integer
Set fs = Application.FileSearch
fs.NewSearch
fs.LookIn = strDirectory
fs.FileName = "*.txt"
If fs.Execute > 0 Then
'MsgBox "There were " & fs.FoundFiles.Count & " file(s) found."
For i = 1 To fs.FoundFiles.Count
'MsgBox fs.FoundFiles(i)
strFile = Left(Right(fs.FoundFiles(i ), Len(fs.FoundFiles(i)) - Len(strDirectory)), Len(fs.FoundFiles(i)) - Len(strDirectory) - 4)
If strFiles <> "" Then
strFiles = strFiles & ";" & strFile
Else
strFiles = strFile
End If
Next i
Else
MsgBox "There were no files found."
End If
Debug.Print strFiles
End Function
and the debug did print my txt files...
BTW the fs.execute parms weren't recognized, but they were also the default value...
Nic;o)
Function RefreshList(strDirectory As String)
Dim fs
Dim strDirectory As String
Dim strFiles As String, strFile As String
Dim i As Integer
Set fs = Application.FileSearch
fs.NewSearch
fs.LookIn = strDirectory
fs.FileName = "*.txt"
If fs.Execute > 0 Then
'MsgBox "There were " & fs.FoundFiles.Count & " file(s) found."
For i = 1 To fs.FoundFiles.Count
'MsgBox fs.FoundFiles(i)
strFile = Left(Right(fs.FoundFiles(i
If strFiles <> "" Then
strFiles = strFiles & ";" & strFile
Else
strFiles = strFile
End If
Next i
Else
MsgBox "There were no files found."
End If
Debug.Print strFiles
End Function
and the debug did print my txt files...
BTW the fs.execute parms weren't recognized, but they were also the default value...
Nic;o)
ASKER
Did you try it in runtime? Any reason why a function is necessary? I removed the the fs.Execute params but no change. I don't have easy access to the database right now or I'd try it as a function...
ASKER
Did you try it in runtime? Any reason why a function is necessary? I removed the the fs.Execute params but no change. I don't have easy access to the database right now or I'd try it as a function...
Oops, I only own a A2000 runtime version...
The function was created because I was too lazy to create a form too..
Theoretically it should ofcourse work in both .mdb form and runtime, but I guess we know M$ ;-(
I can drop my function sample, but I guess that won't help much.
I would start with a compile of the .mdb before the creation of the runtime version (just to be sure other error's don't cause this)
Also a reinstall of Access and a check for patches on the M$ site could be usefull and as a workaround you could consider to switch to using the "good old" DIR command....
Nic;o)
The function was created because I was too lazy to create a form too..
Theoretically it should ofcourse work in both .mdb form and runtime, but I guess we know M$ ;-(
I can drop my function sample, but I guess that won't help much.
I would start with a compile of the .mdb before the creation of the runtime version (just to be sure other error's don't cause this)
Also a reinstall of Access and a check for patches on the M$ site could be usefull and as a workaround you could consider to switch to using the "good old" DIR command....
Nic;o)
ASKER
Is there a way to use DIR to do the same thing? I'm simply getting a listbox of valid files from the selected directories. I use DIR now but only as verification of a known file existing... If there are other methods, I'm open to just about anything right now... :) I will check for updates.
Thanks!
JS
Thanks!
JS
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey, it may be old fashioned, but if I can get it to work I'll be thrilled with it!
Thanks,
JS
Thanks,
JS
ASKER
It works well... I left out the sort and the table for now... If they decide they want it, I can add it in later. :)
Thanks!
JS
Thanks!
JS
Function RefreshList(strDirectory As String)
Dim fs
Dim strDirectory As String
Dim strFiles As String, strFile As String
Dim i As Integer
Set fs = Application.FileSearch
fs.NewSearch
fs.LookIn = strDirectory
fs.FileName = "*.txt"
If fs.Execute > 0 Then
'MsgBox "There were " & fs.FoundFiles.Count & " file(s) found."
For i = 1 To fs.FoundFiles.Count
'MsgBox fs.FoundFiles(i)
strFile = Left(Right(fs.FoundFiles(i
If strFiles <> "" Then
strFiles = strFiles & ";" & strFile
Else
strFiles = strFile
End If
Next i
Else
MsgBox "There were no files found."
End If
Debug.Print strFiles
End Function
and the debug did print my txt files...
BTW the fs.execute parms weren't recognized, but they were also the default value...
Nic;o)