Need help converting code to work with 2007

marubal21

Registered User.
Local time
Today, 13:25
Joined
Mar 24, 2010
Messages
13
Hello,
I'm using a module i had for an access 2003 DB using ".FileSearch" property, but my computers at work have upgraded to access 2007. Could some body please help me convert this section of code to work on 2007?

This is the error msg i get when i use my current code.
"You entered an expression that has an invalid reference to the property FileSearch."

I've looked around and found that its because access 2007 doesn't support it anymore i just don't have the programming skills to figure it out.

fn = CurrentProject.Path & "\Imports\"
Set fs = Application.FileSearch
With fs
.LookIn = fn
 
Here is how I import xls files from a directory with Access 2007...

Code:
    Dim sNetworkPath As String
    Dim sFileName As String
    Dim lCount As Long

    Dim objFS As Object
    Dim objFolder As Object
    Dim objFiles As Object
    Dim objF1 As Object

    sNetworkPath = "\\Server\Directory\"
    sFileName = Dir(sNetworkPath & "Test" & "*.xls")

    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFS.GetFolder(sNetworkPath)
    Set objFiles = objFolder.Files

    CurrentDb().Execute "DELETE * FROM MyTestTable"

    For Each objF1 In objFiles
        If Left(objF1.Name, 4) = "Test" And Right(objF1.Name, 3) = "xls" Then
            DoCmd.TransferSpreadsheet acImport, , "MyTestTable", sNetworkPath & sFileName, True
            sFileName = Dir()
            lCount = lCount + 1
        End If
    Next

    Set objF1 = Nothing
    Set objFiles = Nothing
    Set objFolder = Nothing
    Set objFS = Nothing

I think this also requires a reference set to the microsoft scripting runtime.
 

Users who are viewing this thread

Back
Top Bottom