• Catching and replacing warning messages (A2K Sr1)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Catching and replacing warning messages (A2K Sr1)

    Author
    Topic
    #374336

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #605281

      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.

      • #605378

        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.

    Viewing 0 reply threads
    Reply To: Catching and replacing warning messages (A2K Sr1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: