Use DIR command to append file names to table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to use the dir command to look through a folder c:\Data.

Is it possible to use the dir command to look through the folder and each
time run an append query that will insert a record with the name of the file?

I have looked at the example in the help file for dir but to be honest i
can't really make head nor tail of it.

I'm using windows xp and Access 2000.

Thanks in advance for any help or suggestions
 
An append query? Sounds like overkill to me.

Why not just open the table as a recordset, and run through the Dir() loop;
every time you find a file name that you want to add to the table, do the
following:
AddNew
!FieldName1 = "something"
!FieldName2 = "etc."
Update
Of course, if the file name you encountered wasn't valid for adding into the
table, bypass the above code.
You can also customize your function, to make sure all files Dir() finds is
valid, like:

txtFileName = Dir("C:\Data\*.doc")

Incidentally, you need only specify the Dir() arguments once, before the loop.
After that, repeated calls to the function should have no arguments, i.e. Dir
() without anything inside the parens.

Hope this helps,

Sam
 
Back
Top