how to create my own message if a user enter a value not match with the data type?

leetie

New member
Local time
Yesterday, 22:48
Joined
Nov 16, 2005
Messages
5
In MS Access form, how can I create my own message if the user enter a value that not match with the data type of a field in underlying table? Thanks a lot!
 
Hello

You can do this in the table or form. In the form for your control look at the "Validation Rule" and "Validation Text" properties.
'
Place your rule in the Validation Rule property. Place your message in the Validation text when the entry is not correct.
Regards
Mark
 
Thanks mhartman! but I means that if a user enter a string into a field with data type number, MS Access always turn on th standard message: "The value you entered isn't valid for this field...". I can't use the validation rule to solve it.
Example, if data type of a field is number (field size: byte), I want to create my own message if a user enter a value <0 or >255.
 
Hello Again:

What you want to do is set the SetWarnings to false.
'
SetWarnings Method
See Also Applies To Example Specifics
The SetWarnings method carries out the SetWarnings action in Visual Basic.

expression.SetWarnings(WarningsOn)

expression Required. An expression that returns one of the objects in the Applies To list.

WarningsOn Required Variant. Use True (–1) to turn on the display of system messages and False (0) to turn it off.

Remarks
For more information on how the action and its argument work, see the action topic.

If you turn the display of system messages off in Visual Basic, you must turn it back on, or it will remain off, even if the user presses CTRL+BREAK or Visual Basic encounters a breakpoint. You may want to create a macro that turns the display of system messages on and then assign that macro to a key combination or a custom menu command. You could then use the key combination or menu command to turn the display of system messages on if it has been turned off in Visual Basic.

Example
The following example turns the display of system messages off:

DoCmd.SetWarnings False

Regards
Mark
 

Users who are viewing this thread

Back
Top Bottom