On Wed, 08 Nov 2006 12:51:55 GMT, sparks wrote:
If Not IsNull(DLookup([Office_use], "tblDemographic", "[Office_use] =
""" & Me.Text9 & """")) Then
Cancel = True
MsgBox "Duplicate Value is Not Allowed"
ActiveControl.Undo
DoCmd.RunCommand acCmdUndo
End If
I try to do this but when you enter a text value such as A you get
"you canceled the previous operation"
and the debugger is on the IF line of the command so cancel is not
true or ??
never seen this kind of error before
Each argument of a DLookUp must be a string. Your first arghument is
not a string,....(If Not IsNull(DLookup([Office_use],....).
[Office_use] needs to be enclosed in Quotes, as are the other
arguments.
If Not IsNull(DLookup("[Office_use]", ...etc..) would most likely
work, but it would me simpler to just count.
If DCount("*","tblDemographic", "[Office_use] = """ & Me.Text9 & """")
0 Then
MsgBox "Duplicate Value is Not Allowed".
Cancel = True
ActiveControl.Undo
End If
As long as Cancel is an accepted argument in the sub procedure you are
writing this code, i.e. a Control's BeforeUpdate event, Cancel = True
is all you need. The DoCmd.RunCommand acCmdUndo should not be
necessary.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail