Use DIR command to append file names to table

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
 
O

OfficeDev18 via AccessMonster.com

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top