Question : VBA Logic

I need a peice of code to do the following....
Look in qry_DocumentRegister_Redundant in column Filename
Check to see if each of the Filenames exist in any of the 5 directories specified
c:\xyz\a
c:\xyz\b
c:\xyz\c
c:\xyz\d
c:\xyz\e
If they do then move the files to directory
c:\abc\a
Else do nothing

One other problem, the Filename in the query does not include a file type ending only the Filename itself and the files in the directory could be any filetype.

Thanks

Answer : VBA Logic

It sounds like the filename that is stored in your table already contains the period (.) which sets it off from the file extension, or that the filename stored in your table is not complete.  Try:

strFileName = Dir("f:\Test Directory\Live\" & FName & "*.*") this does not work

The reason it is finding the same file every time is that you are not removing the file you just found, you are copying it.  In your original post you said: "If they do then move the files to directory".  But the FileCopy command does not move the file, it just copies it.  That I why in my most recent code you will see that I renamed the file, which actually moves it to the new directory.

Name "C:\Access\test\Source\" & strFileName As "C:\Access\test\Destination\" & strFileName

Also, if you use the Dir( ) function and pass it a foldername each time, it will return the first file in the folder, every time.  If you actually want to display all of the files in a folder, you would have to use something like:

strFileName = Dir("f:\Test Directory\Live")
debug.print strFileName
Do
    strFileName = Dir()
    debug.print strFileName
Loop while Len(strFileName) > 0

Also, the code you are using will not search for a second or third file with the same file extension.  It will just bypass those.  If that is not an issue then then leave your code the way it is.  If that could be an issue then you need to look at my most recent code segment and copy that logic.
Random Solutions  
 
programming4us programming4us