Importing csv files Access 2007 error 2455

tugsy

New Member
Joined
Aug 29, 2005
Messages
26
I had a module for importing csv files into a Access database. I have since upgraded (or downgraded as it seems) to Office 2007.

Now when I run the macro I get this error:

Run-time error '2455':

You entered an expression that has an invalid reference to the property FileSearch.

Here is my module:
Code:
Sub ImportWorkbooks()
    Dim FilesToProcess As Integer
    Dim i As Integer
    Dim ThisEntry
    Const TOP_FOLDER = "D:\calls2008" 'adjust folder name to suit
    
    With Application.FileSearch
        .NewSearch
        .LookIn = TOP_FOLDER
        .SearchSubFolders = True
        .Filename = "*.csv"
        .Execute
        FilesToProcess = .foundfiles.Count
        
        For i = 1 To FilesToProcess
          'import each file
          DoCmd.TransferText acImportDelim, "phone_import_specs", "PhoneData", .foundfiles(i), True
        Next i
    End With
End Sub

Any help would be appreciatated.
Thanks,
Tugsy
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I discovered that Application.FileSearch is apparently no longer supported. Google search.

Is there an alternative to do this?
 
Upvote 0
With a little bit of searching I found this:

Code:
dim sFile

sFile=Dir(pathToFolder & "\*.*")

while sFile<>""
           listfiles=listfiles & ";" & sfile

       sFile=Dir
wend

and incorporated some of the original code

Code:
Sub ImportWorkbooks()
       
    Dim sFile
    Dim foundfiles
sFile = Dir("D:\Shared\calls2008\*.*")

While sFile <> ""
           foundfiles = "D:\Shared\calls2008\" & sFile
        DoCmd.TransferText acImportDelim, "phone_import_specs", "PhoneData", foundfiles, True
       foundfiles = ""
       sFile = Dir

Wend
End Sub

All I have to do is copy the files I want to import into the directory and then run it.

I hope this can help somone else with similar problems.
 
Upvote 0
Thanks Tugsy. There was a thread a while back that covered a few options for FileSearch replacements. Apparently it was dropped by mistake, and will be back in the next version.

Denis
 
Last edited:
Upvote 0
Re: Importing files to Access 2007 error 2498

I have a similar problem and tried to apply the changes recommended. I now get a RTE 2498 '...wrong data type for one argument' (the debug highlights the DoCmd line). I got the original code from this forum and am only savvy enough to try and replicate changes - I am no expert by any means...

I have several files in the ...\Loans folder, all of which have a named range called "Debt_Schedule". I want to import all of the information in these named ranges into a table called "Loans".

Any help you can provide that troubleshoots this code is most appreciated:

Function ImportWorkbooks()
Dim sFile
Dim foundfiles

sFile = Dir("T:\Debt Management\Loan Tracking\Loans\*.*")
While sFile <> ""
foundfiles = "T:\Debt Management\Loan Tracking\Loans\" & sFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Loans", "Debt_Schedule", foundfiles, True
foundfiles = ""
sFile = Dir
Wend
End Function
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,327
Members
451,697
Latest member
pedroDH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top