Custom Validation Text message

G

Guest

Hey everyone,

In my table, when a user enters a value that doesn't match my validation
requirements, it prompts them with an error message. I've customized the
'Validation Text' field so a custom message comes up.But, is it possible to
display the "current entry" on this message (the actual entry that prompted
the error)?

I.E. If a person types the number "200" in a field validated to only
accepts 100 or less, I would like the mssage to say something like: "200 does
not fall within the specific range. Please try again."

Any help would be appreciated. Thanks!
 
L

Larry Daugherty

Tables don't offer much in the way of user interface tools. To do
what you want, do your validation in code at the form level and use a
message box.

HTH
 
G

Guest

Would you be able to tell me where and how the code would be written on the
form field?
 
F

fredg

Would you be able to tell me where and how the code would be written on the
form field?

Here's how you can find the correct error and show your own message
for any of the form level errors.

First code the Form's Error event:

MsgBox "Error#: " & DataErr ' Display the error number
Response = acDataErrDisplay ' Display Default message

Then open the form and intentionally make that error.

The message box will display the error number and the default error
message.

Next, go back to the error event and change that code to:

If DataErr = XXXX Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Please enter data in all required fields."
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.

I believe your Validation Rule error raises error # 7753
So code your form's Error event:

If DataErr = 7753 Then
MsgBox "Your entry of " & Me![YourControlName].Text & " must be
less than 100."
Else
MsgBox "Error#: " & DataErr
End If
Response = acDataErrContinue

The error message will read:
"Your entry of 200 must be less than 100."
 
G

Guest

That worked PERFECTLY. Thanks Fred!

fredg said:
Would you be able to tell me where and how the code would be written on the
form field?

Here's how you can find the correct error and show your own message
for any of the form level errors.

First code the Form's Error event:

MsgBox "Error#: " & DataErr ' Display the error number
Response = acDataErrDisplay ' Display Default message

Then open the form and intentionally make that error.

The message box will display the error number and the default error
message.

Next, go back to the error event and change that code to:

If DataErr = XXXX Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Please enter data in all required fields."
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.

I believe your Validation Rule error raises error # 7753
So code your form's Error event:

If DataErr = 7753 Then
MsgBox "Your entry of " & Me![YourControlName].Text & " must be
less than 100."
Else
MsgBox "Error#: " & DataErr
End If
Response = acDataErrContinue

The error message will read:
"Your entry of 200 must be less than 100."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top