Results 1 to 8 of 8
  1. #1
    AlisonP is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Northern CA
    Posts
    13

    How to trap and change the default data type validation error?

    Hi folks, I've been teaching myself Access programming and am new to this forum. I have looked here and elsewhere for a problem but have not found a solution, hoping someone here can help.



    In a form control, I am doing a number of data checks and generating appropriate error messages, using VB in the "on exit" event. The field I am checking is declared as data type number in the underlying table. If the user mistakenly enters text, Access generates an error "The value you entered isn't valid for this field." I want to change that default error message. I have learned how to change other default error messages, but I can't figure out how to trap and change this one. Note -- I don't want to check for the error in the form, because there are a dozen or so controls in the form where I need to do this check.

    I would be most grateful for help.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Data errors like that are caught in the form's error event. You should be able to trap it there and do what you want.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    AlisonP is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Northern CA
    Posts
    13
    Thanks for the quick reply, Paul. As I said in my post, I do not want to trap in the form error, as there are about a dozen individual controls on the form where I want to trap this error, and have a different error message for each control.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I thought you meant you didn't want to check control by control. I'm not sure you have any option other than the form error event. That error is going to fire as soon as you try to enter the bad value, and I believe the form error event fires before the control's before update event, so you can't try to catch it there. I suspect you'll have to go with unbound controls so you can do all your validation yourself. You could also have all your code in the form error event, test for which control is throwing the error and return the appropriate message (you can probably use the tag property of the control for the message).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    AlisonP is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Northern CA
    Posts
    13
    Thanks Paul. Yes, I do want to check control by control. So I see now that I can see this error in the form control event; it's error 2113. Pardon me, but I am newbie here, learning much. How do I check control by control in the form error event which of the controls is generating the error? Many thanks.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    To clarify, the form error event will fire as soon as you enter bad data in a control. It's not going to wait and do multiple controls at once. This is giving me the info about the error and the control that threw it:

    MsgBox "you're in the form error event, error: " & DataErr & " for control named " & Screen.ActiveControl.Name & " which has a tag property of " & Screen.ActiveControl.Tag
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    AlisonP is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Northern CA
    Posts
    13
    Thank you Paul!!!! Yes, that can indeed do what I want. I did not know about the Tag property, very useful in this application. Thank you for teaching me so much!

    I am just retired, and am learning Access for fun (geek at heart!), and so that I can volunteer my time to build Access databases for non-profits. I am learning Access on my first small project for a local non-profit. Just discovered this forum, and so appreciate that you have helped me.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help, and welcome to the site by the way! If you're in NorCal, you're just over the hill from me; I'm in Reno. Stop sending all the rain and snow up here!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 02-22-2011, 11:14 AM
  2. change data type in make table query
    By jgelpi16 in forum Queries
    Replies: 2
    Last Post: 01-26-2011, 09:37 AM
  3. Data type mismatch error on all of my queries!
    By MarkGLyons in forum Queries
    Replies: 3
    Last Post: 12-27-2010, 01:27 PM
  4. Data validation warning vs error
    By mafrank101 in forum Access
    Replies: 3
    Last Post: 07-14-2010, 05:05 PM
  5. Replies: 7
    Last Post: 11-22-2009, 02:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums