T
tiger0268 via AccessMonster.com
As a startup script, I am wanting to scan a drive for files and copy the
filenames into my table, which I have running fine, but I can seem to stop it
from copying files that are already in the table. My table is called
"tblFiles" and the first field is called "files", which has a text value. I
am just a little inexperienced with recordsets so any help would be greatly
appreciated.
Dim fldr, fls, fl
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set fs = CreateObject("Scripting.FileSystemObject")
Set fldr = fs.GetFolder("FileLocation")
Set fls = fldr.files
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblFiles")
On Error Resume Next
For Each fl In fls
rst.MoveFirst
rst.FindFirst "[files] = '" & fl.name & "'"
If rst.NoMatch Then
rst.AddNew
rst.Fields(0) = fl.Name
rst.Update
DoEvents
End If
Next fl
On Error GoTo 0
rst.close
Set rst = Nothing
Set db = Nothing
filenames into my table, which I have running fine, but I can seem to stop it
from copying files that are already in the table. My table is called
"tblFiles" and the first field is called "files", which has a text value. I
am just a little inexperienced with recordsets so any help would be greatly
appreciated.
Dim fldr, fls, fl
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set fs = CreateObject("Scripting.FileSystemObject")
Set fldr = fs.GetFolder("FileLocation")
Set fls = fldr.files
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblFiles")
On Error Resume Next
For Each fl In fls
rst.MoveFirst
rst.FindFirst "[files] = '" & fl.name & "'"
If rst.NoMatch Then
rst.AddNew
rst.Fields(0) = fl.Name
rst.Update
DoEvents
End If
Next fl
On Error GoTo 0
rst.close
Set rst = Nothing
Set db = Nothing