Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Feb 2002
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Catching and replacing warning messages (A2K Sr1)

    In my table, there is field set as Required, whose value is input from a text box in a form. When a user doesn't key in a value or the value is changed from a filled value to Null and move away from the text box, I receive the expected alert message that
    "The field 'fldName' cannot contain a Null value because the Required Property for this field is set to True. Enter a value in the field."

    How could I catch this alert message and replace it with a message (in a different language) of my own? There is no error number displayed on the screen. I tried to use LostFocus() without success when I moved away from the text box. Can anyone help?

    Generally, is there any way that I can change the built-in warning message like "The text you entered isn't an item in the list." when one keys in an item not in the listbox? I want to replace them with messages of my own.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Catching and replacing warning messages (A2K Sr1)

    You can solve this in various ways.

    (1) Use the BeforeUpdate event of a text box (or other control) to check if the contents are empty. If so, issue a MsgBox with your own warning message and set the Cancel argument of the BeforeUpdate event procedure to True, in order to cancel updating the text box.

    (2) Use the OnError event of the form as a whole. The Form_Error event procedure has two arguments: DataErr is the error number and Response can be set by the programmer. It might be a good idea to start by displaying the error number and corresponding text - you get the text from AccessError(DataErr).
    Later on, you can create a case statement to handle various errors and respond to them in different ways.

    Response can be:
    acDataErrContinue - suppress the built-in Access error message
    acDataErrDisplay - show the built-in Access error message.

    (3) Combo boxes (I suppose you mean this instead of list boxes) have a OnNotInList event. The NotInList event procedure has two arguments: NewData is the string entered by the user and Response can be set by the programmer.

    Response can be:
    acDataErrAdded - tell Access that you have added the NewData to the list; suppress the built-in Access error message.
    acDataErrContinue - suppress the built-in Access error message
    acDataErrDisplay - show the built-in Access error message.

    If you do a search for "NotInList" in this Forum, you'll find examples of code for the NotInList event procedure.

  3. #3
    2 Star Lounger
    Join Date
    Feb 2002
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Catching and replacing warning messages (A2K Sr1)

    Thanks for your prompt and thorough reply. I use method(1) to catch the error. Method (2) didn't work as it didn't catch the error - it didn't catch error due to null value for a required field. Method(3) works for my combo boxes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •