I went with the .Undo method of the Form which has eliminated the Access
error that was being displayed. However, its not quite what I'm looking
for.
The code below basically does what I'm looking except for the Access
error
that's presented on the first time the user attempts to enter an invalid
value.
1) User goes to the new record place holder on the form.
2) User enters a value
3) The value is validated as invalid
4) My msgbox is displayed
5) Access displays its own error - "The value violates the validation
rule
for the field or record" yadda, yadda, yadda, press OK or HELP.
6) User re-enters an invalid value, only my msgbox is displayed. (The
Access
error is never presented again.)
6)
If ECount("txtTrailerDOTNumber", "tblTrailerInventory",
"[txtTrailerDOTNumber] = '" & Me.txtTrailerDOTNumber.Text & "'") = 0
Then
MsgBox "Trailer #" & Me.txtTrailerDOTNumber.Text & " does not
exist
in the database.", vbInformation
Cancel = True
End If
:
You are using the before update event for the control (and not the
form)
To get the value from the control inputTrailerDOTNumber, you can't just
use
Me.inputTrailerDOTNumber ,
instead use Me.inputTrailerDOTNumber.Text
This is necessary because the control inputTrailerDOTNumber has the
focus
when that code is called.
I don't know much about your database, but from the little that is
posted
here, I question why you would want to do this check anyway.
Is it because you are trying to catch an incorrect entry for that
control?
If you already know the inputTrailerDOTNumber, why not just
pre-populate the
control with that value?
Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
"David C. Holley" <David.C.Holley> wrote in message
Nope. Still getting it after MsgBox.
Private Sub inputTrailerDOTNumber_BeforeUpdate(Cancel As Integer)
If ECount("txtTrailerDOTNumber", "tblTrailerInventory",
"[txtTrailerDOTNumber] = '" & Me.inputTrailerDOTNumber & "'") = 0
Then
MsgBox "Trailer #" & Me.inputTrailerDOTNumber & " does not
exist in
the database.", vbInformation
DoCmd.SetWarnings False
Me!inputTrailerDOTNumber.Undo
Cancel = True
DoCmd.SetWarnings True
End If
End Sub
If I nix the Cancel = True, the error is supressed, however I'm left
with
the problem of clearing the value and retuning the user to the field.
If I
call the .SetFocus function, I get an error about having to save the
record first. If I try to explicity set the value, I get an error.
Its
been quite awhile since I've had to deal with validation in Access
and its
driving me nuts.
Try using:
DoCmd.SetWarnings False
then in your exit routine:
SoCmd.SetWarnings True
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access
"David C. Holley" <David.C.Holley> wrote in message
I'm using the following routine to validate a value entered by a
user.
Access
is throwing an error - The value violates the validation rule for
the
field
or record.
How can I supress the error?
Private Sub inputTrailerDOTNumber_BeforeUpdate(Cancel As Integer)
If ECount("txtTrailerDOTNumber", "tblTrailerInventory",
"[txtTrailerDOTNumber] = '" & Me.inputTrailerDOTNumber & "'") = 0
Then
MsgBox "Trailer #" & Me.inputTrailerDOTNumber & " does not exist in
the database.", vbInformation
Cancel = True
Me!inputTrailerDOTNumber.Undo
End If
End Sub
.