If DCount("*","TableName","[FieldName] = " & Format(Me![ControlName],
"\#mm\/dd\/yyyy\#"))
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Hi,
My field is a Date/Time format. When I enter this expression you gave
:
If DCount("*","TableName","[FieldName] = '" & Me![ControlName] &
"'")
0 Then
MsgBox "This item already exists in the table."
Cancel = True
End If
I have an error of Data type mismatch. I tested with a ''Text'' field
and
it works, but I really need the field to be ''Date/Time. Can it be
possible ?
THanks,
:
Thank you very much. This was very helpful. It worked perfectly!
--
Glenn
:
On Wed, 10 Aug 2005 11:56:48 -0700, Glenn wrote:
Can Access recognize a duplicate value in an indexed (Yes, no
duplicates)
field as soon as you type it in and exit that field? Currently,
Access lets
you enter all data on a form and then when you try to move to
the
next form
you get the error message stating you have a duplicate value.
Is the Field a Text datatype?
Code that control's BeforeUpdate event:
If DCount("*","TableName","[FieldName] = '" & Me![ControlName] &
"'")
0 Then
MsgBox "This item already exists in the table."
Cancel = True
End If
If it is a Number datatype:
If DCount("*","TableName","[FieldName] = " & Me![ControlName]) > 0
Then
etc.