Microsoft Knowledge Base Email Alertz

Error message when you try to run the FileSearch function in Access 2007: You entered an expression that has an invalid reference to the property FileSearch

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 935402 - Last Review: April 5, 2007 - Revision: 1.0

Error message when you try to run the FileSearch function in Access 2007: "You entered an expression that has an invalid reference to the property FileSearch"

SYMPTOMS

When you try to run the FileSearch function in Microsoft Office Access 2007, you receive the following error message:
You entered an expression that has an invalid reference to the property FileSearch.
This problem occurs if the FileSearch function was created in an earlier version of Access.

CAUSE

The File Search task pane and the FileSearch object have been removed from the 2007 Microsoft Office programs.

RESOLUTION

To programmatically search for a file in Access 2007, you can use either the Dir function or the FileSystemObject class.

For more information about the Dir function, visit the following Microsoft Web site:
http://office.microsoft.com/en-us/access/HA012288241033.aspx (http://office.microsoft.com/en-us/access/HA012288241033.aspx)

The FileSystemObject class was originally created for the Microsoft Visual Basic Scripting Edition. The FileSystemObject class is not included in the Visual Basic for Applications object library. To use the FileSystemObject class, you must select Microsoft Scripting Run-time (Scrrun.dll) in the References dialog box for the project.

For more information about the FileSystemObject class, click the following article numbers to view the articles in the Microsoft Knowledge Base:
186118  (http://kbalertz.com/Feedback.aspx?kbNumber=186118/ ) How to use FileSystemObject with Visual Basic
185601  (http://kbalertz.com/Feedback.aspx?kbNumber=185601/ ) How to recursively search directories by using FileSystemObject

MORE INFORMATION

For more information, click the following article number to view the article in the Microsoft Knowledge Base:
920229  (http://kbalertz.com/Feedback.aspx?kbNumber=920229/ ) Error message when you run a macro to search for a file in an Office 2007 program: "Run-time error 5111"

APPLIES TO
  • Microsoft Office Access 2007
Keywords: 
kbexpertiseinter kbtshoot kbprb KB935402
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

PavHabr Report As Irrelevant  
Written: 6/24/2009 9:02 AM
'!!!! Replacement solution including searching in subdirectories !!!! //------------------------------------------------------------------------------------------------ Sub FileSearchByHavrda_Example_of_procedure_calling() ' ' Example of FileSearchByHavrda procedure calling as replacement of missing FileSearch function in the newest MS Office VBA ' 01.06.2009, Author: P. Havrda, Czech Republic ' Dim FileNameWithPath As Variant Dim ListOfFilenamesWithParh As New Collection ' create a collection of filenames ' Filling a collection of filenames (search Excel files including subdirectories) Call FileSearchByHavrda(ListOfFilenamesWithParh, "C:\Temp", "*.xls", True) ' Print list to immediate debug window and as a message window For Each FileNameWithPath In ListOfFilenamesWithParh ' cycle for list(collection) processing Debug.Print FileNameWithPath & Chr(13) MsgBox FileNameWithPath & Chr(13) Next FileNameWithPath ' Print to immediate debug window and message if no file was found If ListOfFilenamesWithParh.Count = 0 Then Debug.Print "No file was found !" MsgBox "No file was found !" End If End Sub //------------------------------------------------------------------------------------------------ Private Sub FileSearchByHavrda(pFoundFiles As Collection, pPath As String, pMask As String, pIncludeSubdirectories As Boolean) ' ' Search files in Path and create FoundFiles list(collection) of file names(path included) accordant with Mask (search in subdirectories if enabled) ' 01.06.2009, Author: P. Havrda, Czech Republic ' Dim DirFile As String Dim CollectionItem As Variant Dim SubDirCollection As New Collection ' Add backslash at the end of path if not present pPath = Trim(pPath) If Right(pPath, 1) <> "\" Then pPath = pPath & "\" ' Searching files accordant with mask DirFile = Dir(pPath & pMask) Do While DirFile <> "" pFoundFiles.Add pPath & DirFile 'add file name to list(collection) DirFile = Dir ' next file Loop ' Procedure exiting if searching in subdirectories isn't enabled If Not pIncludeSubdirectories Then Exit Sub ' Searching for subdirectories in path DirFile = Dir(pPath & "*", vbDirectory) Do While DirFile <> "" ' Add subdirectory to local list(collection) of subdirectories in path If DirFile <> "." And DirFile <> ".." Then If ((GetAttr(pPath & DirFile) And vbDirectory) = 16) Then SubDirCollection.Add pPath & DirFile DirFile = Dir 'next file Loop ' Subdirectories list(collection) processing For Each CollectionItem In SubDirCollection Call FileSearchByHavrda(pFoundFiles, CStr(CollectionItem), pMask, pIncludeSubdirectories) ' Recursive procedure call Next End Sub //------------------------------------------------------------------------------------------------