Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileSearch Object – Office Object Library problem in Access 2002 1

Status
Not open for further replies.

Clarinet

Technical User
Mar 21, 2005
20
US
The following code works fine in Access 2000/Windows 2000:

With Application.FileSearch
.NewSearch
.LookIn = strMoveFrom
.SearchSubFolders = False
.LastModified = msoLastModifiedToday
.FileType = msoFileTypeAllFiles
.Execute msoSortByFileName
More code ………………..
End With

When I copied the app to a Windows XP Home Edition machine with Access 2002 (SP3) the code does not work. Machine hangs on the .Execute msoSortByFileName line and Ctl/Alt/Del is the only way out. I sent the error data to Microsoft per the popup and the suggestion was to update Office 10. I did this and the same error occurred with no suggested fix the second time.

References set in Access 2002 are:
Visual Basic For Applications
Microsoft Access 10.0 Object Library
Microsoft ActiveX Data Objects 2.1 Library
Microsoft Office 10.0 Object Library
OLE Automation

The only difference I can see is that the Reference to MS Office 9.0 library in Access 2000 is not possible to set in Access 2002 (MSO9.DLL is not available in XP/Access 2002). Setting a reference to MS Office 10 in XP does not solve the problem.

Any insight into this would be greatly appreciated.

Thank you.
 
What happens if you use the value for msoSortByFileName, which is:
.Execute 1
 
Remou
Thank you for such a quick suggestion - I did not think of this. I will have to wait until I get home to the XP machine this afternoon to try using the value and will let you know if it worked.
 
Hello Remou
I tried using the value for msoSortByFileName (.Execute 1) and had the same problem. Had to Ctrl/Alt/Del because Access was not responding.

Files included in the error report are:
C:\DOCUME~1\Stan\LOCALS~1\Temp\WERb8ed.dir00\MSACCESS.EXE.mdmp
C:\DOCUME~1\Stan\LOCALS~1\Temp\WERb8ed.dir00\appcompat.txt

Any other suggestions on how to use the FileSearch Object in Access 2002 would be greatly appreciated.
 
You have a different library version problem here. In a case where I had to use the FileSearch outside office I used a trick that might help you

Code:
Function XXX(strMoveFrom As String , more parameters) As String
Dim objWord As Object
Dim FS As Object
Dim bWordRunning As Boolean

On Error Resume Next
bWordRunning = True
Set objWord  = GetObject(,"Word.Application")
If Err<>0 then 
   Err.Clear
   Set objWord  = CreateObject("Word.Application")
   bWordRunning = False
End If
Set FS = objWord.FileSearch
With FS
    .NewSearch
    .LookIn = strMoveFrom
    .SearchSubFolders = False
    .FileType = 1 'msoFileTypeAllFiles
    .LastModified = 2 'msoLastModifiedToday
    If .Execute (1, 1) > 0 Then ' msoSortByFileName, msoSortOrderAscending
       ...
    End If
End With
Set fs = Nothing
If Not bWordRunning Then objWord.Quit
Set objWord = Nothing
End Function
 
Jerry,
Thank you for your suggestion. I tried the code and it does not execute between the bolded lines (for...next loop and msgbox are passed over). The function is called from On_click where the original code started. strCopyFrom is global to the form. Perhaps a simple fix to your code that I cannot see would solve the problem.

Also, do you think it would work if I could import MSO9.DLL from the Microsoft website to C:\Program Files\Microsoft Office\Office\ and set the reference? Just don't know if this would cause other problems.

---------------------------------------------------------
Function BadLibraryVersion()
Dim objWord As Object
Dim FS As Object
Dim bWordRunning As Boolean

On Error Resume Next
bWordRunning = True
Set objWord = GetObject(, "Word.Application")
If Err <> 0 Then
Err.Clear
Set objWord = CreateObject("Word.Application")
bWordRunning = False
End If
Set FS = objWord.FileSearch
With FS
.NewSearch
.LookIn = strCopyFrom
.SearchSubFolders = False
.FileType = 1 'msoFileTypeAllFiles
.LastModified = 2 'msoLastModifiedToday
If .Execute(1, 1) > 0 Then ' msoSortByFileName, msoSortOrderAscending
.Execute 1
For I = 1 To .FoundFiles.Count
.FileName = Application.FileSearch.FoundFiles(I)
Next I

MsgBox .FoundFiles.Count & " of " & UBound(myList) + 1 & " files were copied " & vbCrLf & "FROM: " & _
strCopyFrom & vbCrLf & "TO: " & strDestinationFile & ".", vbInformation, "File Copy Result"

End If
End With
Set FS = Nothing
If Not bWordRunning Then objWord.Quit
Set objWord = Nothing

End Function
 
Code:
    If .Execute(1, 1) > 0 Then  ' msoSortByFileName, msoSortOrderAscending
    [s].Execute 1[/s] executing for 2nd time here!     
    [s].FileName = Application.FileSearch.FoundFiles(I)[/s]
       '.FileName is a propererty of the FS object. Don't use it!
      'Array of the files
       ReDim AllFiles(1 To .FoundFiles.Count)
       For I = 1 To .FoundFiles.Count
          AllFiles(I) = .FoundFiles(I)
       Next I

MsgBox .FoundFiles.Count & " of " & UBound(myList) + 1 & " files were copied " & vbCrLf & "FROM: " & _
strCopyFrom & vbCrLf & "TO: " & strDestinationFile & ".", vbInformation, "File Copy Result"

    End If

I don't know [ponder]
 
Jerry,
That did the trick! Thanks so much for your help and here's a well deserved star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top