Validation rule possibley can mean
(1) validation for the field in the table's design view;
(2) validation for the control on the form in the form's design view;
(3) required property is set to yes;
(4) allow zero length string property is set to no;
(5) wrong data type for the field's data type (e.g., trying to store a
letter in a numeric field)
(6) nonunique value being entered into a field that is required to be
unique;
and perhaps others.
However, I have no idea which step of the code is causing this error, which
control or field is getting a value, etc. Can you give more details?
--
Ken Snell
<MS ACCESS MVP>
Tony Williams said:
Thanks Ken that worked EXCEPT I now get an error message that says the value
in the field violates the validation rule for the field but I haven't got
any validation rules? Can you help?
It's 6.30pm here in the UK and I'm going "screen blind" so if I don't
respond to any further answer until tomorrow please excuse me, I'll just
have to call it a day!
Thanks again
Tony Williams
Ken Snell said:
That's because you want to test for Cancel = False to show the
message,
not
if it's True, the way your expression is set up.
However, assuming that you want to have Cancel be True when there are no
records, use this expression instead:
Cancel = (DCount("*", "tblmonth", "[txtMonth] = #" & Me.txtMonth &
"#")
=
0)
--
Ken Snell
<MS ACCESS MVP>
Thanks Ken used your code but still don't get message
:
Close:
Cancel = DCount("*", "tblmonth", "[txtMonth] = #" & Me.txtMonth & "#")
--
Ken Snell
<MS ACCESS MVP>
Thanks Rick I've tried this
Cancel = DCount(#*#, "tblmonth", [txtMonth] = ## & Me.txtMonth & ##)
If Cancel Then MsgBox "This Quarter already exists."
but I get a syntax error. Could you point me in the right direction?
Yes this is a date field, but it doesn't have any time, the
format
is
Short
Date?
Thanks again
Tony
I am using this code in the before update event on a control to
check
whether the value already exists
Cancel = DCount("*", "tblmonth", [txtMonth] = "" &
Me.txtMonth
exists