Full Version: Dcount Function Does Not Return A Correct Number Of Records
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Lin100
Access 2010. Windows 7

I am trying to test to see if there is already a record with a particular tagname that is enterted on Forms!FrmIOClone!TagName.
If there is no record add that record, but if there is 1 or more record with that tagname then do not add that record.

The code below return 4,053 records when in fact it should be 0.
The code MsgBox DCount("TagName", "tblio", Forms!FrmIOClone!TagName) return 4053 records, when it should return only 0.

When I entered a unique value on Forms!FrmIOClone!TagName and click OK the statement below is not 0 so it branches
to else

If DCount("tblIO.TagName", "tblio", Me.TagName) = 0 Then


/////////////////////////////////////////////////////////////////////////////

Private Sub OKButton_Click()
MsgBox DCount("TagName", "tblio", Forms!FrmIOClone!TagName) <<<---- It gave the total number of records (4053) in the table. It suppose to have 0.

If DCount("tblIO.TagName", "tblio", Me.TagName) = 0 Then
recIO.AddNew ' No. New or Clone mode
Else
MsgBox "This tagname is already in table TblIO. Only one tagname is allowed in the database.", vbCritical, "A tagname must be unique."
Exit Sub
End If
End Sub
theDBguy
Hi,

I think your "criteria" expression is a bit off. Try it this way and see what happens:

If DCount("*", "tblio", "TagName='" & Forms!FrmIOClone.TagName & "'") = 0 Then

Just my 2 cents... 2cents.gif
Lin100
Thank you theDBguy for your help.
theDBguy
Hi,

yw.gif

Glad we could help. Good luck with your project.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.