Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating external files via code

Status
Not open for further replies.

EddyLLC

Technical User
Mar 15, 2005
304
US
Using Access2003 I have a need to look into a directory, and one at a time, rename and move each file there into another directory. The renaming and moving I have an idea how to do, but how do I loop through the files in the directory? There may be up to 10 files in the directory each with a different name.

Thanks for any suggestions.
 
Using file system objects
Code:
    Dim FSO As New FileSystemObject
    Dim FolderName As Folder
    Set FolderName = FSO.GetFolder("yourpathname")
...
    Set FileNames = FolderName.Files
    For Each FileID In FileNames
       ...
       your code here
       ...
    Next

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Thanks for the response Greg and pardon my lack of knowledge. I tried your suggestion and when tested I received an error telling me "Variable Not Defined" on the line "Set Filenames = FolderName.Files". The Variable of course was Filenames. Just to test I dimmed Filenames as Files and then received the error informing me Variable Not Defined referring to the FileID field.

I must be missing the boat. Am I possibly missing a reference?

Thanks
Eddy
 

You need to set a reference (Tools > References...) to:

Microsoft Scripting Runtime (C:\WINNT\system32\scrrun.dll)


TomCologne
 
You may also consider the Dir function and the Name ... As instruction.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the replys. I checked and I did have a reference to Microsoft Scripting Runtime. I then tried the Dir function and was able to get it working.

Thanks again.
Eddy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top