Microsoft KB Archive/259738

= OFF97: Microsoft Office 97 Programs FileSearch Fails on a Microsoft Windows 2000-based Computer =

Article ID: 259738

Article Last Modified on 1/27/2007

-

APPLIES TO


 * Microsoft Office 97 Standard Edition
 * Microsoft Access 97 Standard Edition
 * Microsoft Excel 97 Standard Edition
 * Microsoft PowerPoint 97 Standard Edition
 * Microsoft Word 97 Standard Edition
 * Microsoft Windows 2000 Standard Edition

-



This article was previously published under Q259738





SYMPTOMS
Visual Basic code that references the Application FileSearch object may cause the following error on a computer that is running Microsoft Windows 2000 if the code includes a wildcard character in the FileName property:

Run-time error '5':

Invalid procedure call or argument



RESOLUTION
Use the Dir property to search for the files as shown in the following example. This example requires that you have .mdb files in the My Documents folder.  Copy the sample database Northwind.mdb to the My Documents folder on a computer that is running Windows 2000. In Access 97, create a new database.  Create a module, and then type the following line in the Declarations section if it is not already there: Option Explicit   Type the following procedure: Function TestDir(strPathName) Dim searchFile As String Dim resultString As String Dim fileCounter As Integer Dim messageString As String fileCounter = 0 searchFile = Dir(strPathName)

If searchFile <> &quot;&quot; Then fileCounter = 1 resultString = searchFile & vbCrLf End If

Do While searchFile <> &quot;&quot; searchFile = Dir If searchFile <> &quot;&quot; Then fileCounter = fileCounter + 1 resultString = resultString & searchFile & vbCrLf End If   Loop

If fileCounter = 0 Then messageString = &quot;No files found&quot; Else messageString = &quot;Found &quot; & fileCounter & &quot; file/s named:&quot; _ & vbCrLf & resultString End If   TestDir = messageString End Function   To test this function, type the following line in the Debug window, and then press ENTER: ?TestDir(&quot;C:\My Documents\No*.mdb&quot;) Note that the results are returned to the Debug window. 

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

MORE INFORMATION
If you click Debug in the error message, the line of code that contains the wildcard character is highlighted. For example: .FileName = &quot;No*.mdb&quot; Note that the code in the &quot;Steps to Reproduce the Behavior&quot; section of this article works correctly the first time that you run it; however, any other attempt to run the code is not successful, and you receive the error message that is mentioned in the &quot;Symptoms&quot; section. If you remove the wildcard character from the code, you can run the code successfully again until running the code re-enters the wildcard character into the function.

Steps to Reproduce the Behavior
 Copy the sample database Northwind.mdb to the My Documents folder on a computer that is running Windows 2000.</li> In Access 97, create a new database.</li>  Create a module, and then type the following line in the Declarations section if it is not already there: Option Explicit </li> On the Tools menu, click References, and then click to select the Microsoft Office 8.0 Object Library check box.</li>  Type the following procedure: Function TestSearch(strLookIn, strLookFor) Dim intCount As Integer

intCount = 0

With Application.FileSearch .NewSearch .FileName = strLookFor .LookIn = strLookIn .SearchSubFolders = False .MatchTextExactly = True .FileType = msoFileTypeAllFiles If .Execute > 0 Then intCount = .FoundFiles.Count End If    End With

testSearch = &quot;Files found = &quot; & intCount End Function </li>  To test this function, type the following line in the Debug window, and then press ENTER: ?testSearch(&quot;c:\My Documents\&quot;, &quot;No*.mdb&quot;) Note that the results are returned to the Debug window the first time that you run the code.

If you run the code a second time, you may receive the error message mentioned in the &quot;Symptoms&quot; section. </li></ol>

<div class="references_section">