The criteria of a domain function is a Where condition without the WHERE
keyword. It is an expression that evaluates to yes or no. Your expression
always evaluates to "yes", therefore it counts all the records. You need to
have an expression that looks something like this:
i = DCount("[filename]", "test", "[filename] = '" & vItem & "'")
--
--Roger Carlson
MS Access MVP
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/...UBED1=ACCESS-L
"Carlos" <(E-Mail Removed)> wrote in message
news:C3538EB8-CA06-44FF-A41A-(E-Mail Removed)...
> 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