Hi!
I made a macro for Access 07 to grab all .csv files in a specific folder on a shared drive (the Access database is also located in this same folder). There's about 20-40 .csv files generated each month and once a month I want to be able to grab all of them and dump them into the same table (all .csv files have the same format and no headers). Here is my code:
Private Sub Command1_Click()
Dim Counter As Integer
With Application.FileSearch
.NewSearch
.LookIn = "Y:\CWT\Field\TX23\Output\NDC Prod"
.SearchSubFolders = False
.FileName = Name & "*.csv"
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
For Counter = 1 To .FoundFiles.Count
.FileName = .FoundFiles(Counter)
DoCmd.TransferText , , "LINK Master Table", .FileName, False
DoEvents
Next Counter
MsgBox "Import complete.", vbInformation, "Done"
Else
MsgBox "There were no files found.", vbCritical, "Error"
End If
End With
End Sub
However when I run this I get:" Runtime Error 2455: You entered an expression that has an invalid reference to the property file search"
The Debug highlights "With Application.FileSearch" in the code.
Can anyone help?
Thanks!
I made a macro for Access 07 to grab all .csv files in a specific folder on a shared drive (the Access database is also located in this same folder). There's about 20-40 .csv files generated each month and once a month I want to be able to grab all of them and dump them into the same table (all .csv files have the same format and no headers). Here is my code:
Private Sub Command1_Click()
Dim Counter As Integer
With Application.FileSearch
.NewSearch
.LookIn = "Y:\CWT\Field\TX23\Output\NDC Prod"
.SearchSubFolders = False
.FileName = Name & "*.csv"
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
For Counter = 1 To .FoundFiles.Count
.FileName = .FoundFiles(Counter)
DoCmd.TransferText , , "LINK Master Table", .FileName, False
DoEvents
Next Counter
MsgBox "Import complete.", vbInformation, "Done"
Else
MsgBox "There were no files found.", vbCritical, "Error"
End If
End With
End Sub
However when I run this I get:" Runtime Error 2455: You entered an expression that has an invalid reference to the property file search"
The Debug highlights "With Application.FileSearch" in the code.
Can anyone help?
Thanks!