Rabu, 19 Oktober 2011

Re: [AccessDevelopers] Ascertaining file names

 

Cathy:


Here is some code that should get you to the point where you found each file and have its name.  In the code, I am assuming that the full path to your input folder is in the variable 'MyPath'

  Dim FSO
  Dim FSOFolder
  Dim FF As File
  Dim MyFileName as string
  Dim MyFiles
  
  Set FSO = CreateObject("Scripting.FileSystemObject")
  Set FSOFolder = FSO.GetFolder(MyPath)
  Set MyFiles = FSOFolder.Files
 
  For Each FF In MyFiles
    MyFileName = FF.Name
    If Right(MyFileName,4) = ".PTX" then
 'process your file

End If  
  Next

Doug Steele

On Wed, Oct 19, 2011 at 7:05 AM, Cathy Jupp <cathy.jupp@stoneham.plc.uk> wrote:
 

I have an ongoing need to import text files that were output from another application into an Access table. I will be doing this using VBA code. I know which folder these files will be in, and the file extension. Once each file has been imported I will rename it from something.PTX to something.XTP so that the file is retained but will be ignored by future imports.

The problem I have is that I will never know the file names, and there could be any number of them.

So essentially what I need to do is loop through the following:

open the first file I encounter in the folder with an extension of .PTX
import it
rename it

until no files with a .PTX extension remain.

I have no idea how to open a file for import within Access without knowing its name. Can anyone advise me how to go about this please?

Many thanks in advance.

Cathy


__._,_.___
Recent Activity:

Please zip all files prior to uploading to Files section.
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar