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
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