G
Guest
Hello All,
I need some help sorting out a syntax problem with the DCount function. I
am trying to fill in file names from a specific folder to a table and exclude
any file names that may already be in the table. Here is the code I am using:
Function Findit()
Dim vItem As Variant
Dim db As DAO.Database
Dim i As Integer
Set db = CurrentDb
With Application.FileSearch
.filename = strFileName
.LookIn = "G:\Test Managment\Proposed Tests"
.SearchSubFolders = True
.Execute
For Each vItem In .FoundFiles
'Check if record exist using the dcount
i = 0
i = DCount("[filename]", "test", "" & Chr(34) & vItem & Chr(34) & "")
If i = 0 Then
db.Execute "INSERT INTO Test (Filename) " & _
"VALUES(" & Chr(34) & vItem & "#" & _
vItem & "#" & Chr(34) & ")", _
dbFailOnError
End If
Next vItem
End With
Set db = Nothing
End Function
The crieteria section of DCount is incorrect because it is counting the # of
records in the table and not the # of records with the value of vItem.
Any suggestions would be greatly appreciated.
Thanks
Carlos
I need some help sorting out a syntax problem with the DCount function. I
am trying to fill in file names from a specific folder to a table and exclude
any file names that may already be in the table. Here is the code I am using:
Function Findit()
Dim vItem As Variant
Dim db As DAO.Database
Dim i As Integer
Set db = CurrentDb
With Application.FileSearch
.filename = strFileName
.LookIn = "G:\Test Managment\Proposed Tests"
.SearchSubFolders = True
.Execute
For Each vItem In .FoundFiles
'Check if record exist using the dcount
i = 0
i = DCount("[filename]", "test", "" & Chr(34) & vItem & Chr(34) & "")
If i = 0 Then
db.Execute "INSERT INTO Test (Filename) " & _
"VALUES(" & Chr(34) & vItem & "#" & _
vItem & "#" & Chr(34) & ")", _
dbFailOnError
End If
Next vItem
End With
Set db = Nothing
End Function
The crieteria section of DCount is incorrect because it is counting the # of
records in the table and not the # of records with the value of vItem.
Any suggestions would be greatly appreciated.
Thanks
Carlos