Script Runs in 2003 / Fails in 2007 (FILE SEARCH)

  • Thread starter RayportingMonkey
  • Start date
R

RayportingMonkey

I recently upgraded from Access 2003 to 2007; since that time, the VBA script
in this post has failed to run. Instead, it generates the following error:

Run-time error ‘2455’:
You entered an expression that has an invalid reference to the property
FileSearch.

The script is as follows;

Option Compare Database
Option Explicit

Sub ImportBatch()

'This code will import/append all the specified
'file types (i.e. all txt files) into the
'applicable table.

'Set Project Variables
Dim PrjPath As String
PrjPath = Application.CurrentProject.Path
Dim Fls As Integer

'Change the following variables depending
'on your requirements.
Dim SrchDir As String
SrchDir = "U:\MyPathGoesHere"
Dim FileType As String
FileType = "*.txt"
Dim TblNam As String
TblNam = "TABLE_NAME_GOES_HERE"
Dim SpecNam As String
SpecNam = "Import Specification Name"

'This is the code that imports the applicable files
'into the tabel specified above.
With Application.FileSearch
.NewSearch
.LookIn = SrchDir
.SearchSubFolders = False
.FileName = FileType

If .Execute() > 0 Then

'MsgBox "There were " & .FoundFiles.Count & " file(s) found."

For Fls = 1 To .FoundFiles.Count

'MsgBox .FoundFiles(Fls) 'Displays the full File Name found

DoCmd.OpenTable TblNam, acViewNormal, acEdit
DoCmd.TransferText acImportDelim, SpecNam, TblNam,
..FoundFiles(Fls), True, ""
DoCmd.Close acTable, TblNam
Next Fls
Else
MsgBox "There were no files found."
End If
End With

End Sub


Thanks in adance for your assistance!

Later-
Ray
 
D

dymondjack

http://www.utteraccess.com/forums/printthread.php?Cat=&Board=84&main=1225204&type=thread
try there... I'm not sure myself (still on 03) but seems like a decent place
to start.


So anyway, now that I've read the thread, and followed to the thread it
pointed to and read that one as well, I could just give the answer instead of
making everyone else read it also...

Application.FileSearch functionality has been removed from Access 2007. Use
Dir() or the FileSystemObject instead.


--
Jack Leach
www.tristatemachine.com

- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top