Full Version: Trap input mask error
UtterAccess Forums > Microsoft® Access > Access Forms
argeedblu
On an unbound form, I have a control for postal code with an input mask that matches the Canadian ANA NAN postal code format. On the same form, I have a command button to allow the user to clear all the form's controls.
The problem at hand is that if the postal code control is only partially completed and the user decides to abort the current form contents, Access generates an input mask error. I would like to avoid having the error appear and simply blank the control.
Any suggestions?
Glenn
freakazeud
Hi Glenn,
Have a look at this example!
Set some form of flag to check to see if the error occured because of the user button press (maybe a hidden checkbox). This way if the hidden checkbox is checked then the button was pressed and therefor ignore the error, if not then give error message.
HTH
Good luck
cheekybuddha
Hi Glenn,
You could use the form's OnError event. From a quick test it would seem that you need to trap for DataErr = 2279.
CODE
Option Compare Database
Option Explicit
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    
    'MsgBox DataErr & ": " & Response
    If DataErr = 2279 Then
        Me.Text0 = ""
        Response = acDataErrContinue
    End If
    
End Sub

hth,
d
JimCagle
Here are a couple of KB articles dealing with "trapping" input mask errors Maybe they will point you in the right direction.....
This and another
argeedblu
Once again, UA Rocks!!
any thanks freakazeud, cheeky, and Jim Cagle for the prompt and great responses to my dilemma. Problem solved. My only issue now is how to tuck the info away for future reference so that I can use the same solution the next time I run into the problem. That will no doubt be many months down the road.
Thanks again!
Glenn
freakazeud
You're welcome.
Glad I could assist frown.gif
Solution: Use FireFox and use its good bookmark manager. Bookmark this thread and voila you will never lose the recources.
Good luck on future projects!
argeedblu
Thanks for the tip.
have been leary of bookmarks since my system crashed and I had to reinstall Windows a year ago. At that time I had a lovely collection of bookmarks in my IE favorites. Unfortunately, I was pretty lax with backuping up. While I didn't lose a lot of important data, I lost whatever was in my Windows folder.
I will have to take a look at Firefox and the bookmark manager.
Glenn
freakazeud
Sorry to hear about your crash!
cheekybuddha
Glenn,
ald we could help.
Happy New Year to you all.
d
argeedblu
This is really a tiny problem but I can be a bit of a perfectionist at times.
The form error trap works as expected (in conjuction with a hidden checkbox to indicate if we are checking the clear button.
The glitch I'd like to solve now may not be solveable. If the user moves to the clear button while the Postal Code control is the active control, he or she must click the command button twice to clear the form. The first click triggers the form error handler which cleans up the Postal Code control and lets us out of it. The second click triggers that actual form clearing code.
HAs I say, this is a minor problem and I actually just solved it as I was typing this post (simply call the command buttons click event from the error handler.
Man you are good!! You solved this one for me before I had even posted it. o!
Glenn
freakazeud
frown.gif
I was going to suggest that. I'm not sure why you have to click the button twice, but if so then just call the click event in the error evaluation, BUT...couldn't you also just provide the clearing code directly in the evaluation rather then calling the button click event again?
argeedblu
I don't think so. What is happening as far as I can tell is that the first click never gets to the button's on_click code. The attempt to click triggers the entry mask's validation and triggers the entry mask error. In essence, the click gets discarded in the process. The button needs its code to clear the whole form under most circumstances. The one exception occurs when the user attempts to leave the one control that has an entry mask. In that case the button's code doesn't get called until the error handler calls it.
That seems to be the logical explanation anyway.
Glenn
freakazeud
Yeah that seems to make sense.
The error code will interrupt the on click event and therefor never fire it. Ones the error code fired there is no error anymore when the button is clicked again and that's why it executes.
argeedblu
Yep, and calling the click event code from the error handler makes for a more seamless UI because the second click is not needed anymore.
Glenn
freakazeud
Yep frown.gif
Glad we got to discuss this!
stephensaid
Hi All,
Is it possible to disable the command button when clicked the first time and enable it again on any input.
From my humble opinion. I' just a starter to this so please guide me if i said anything stupid.
Happy 2006 to all
Stephen
Jack Cowley
You can set the command buttons Enabled property to False but you will have to do it in the On Enter event of the next control in the tab order or some other event. You cannot set a controls Enabled property False if the control (your command button) has the focus. In the forms On Load event or in the On Current event you can set the command buttons Enabled property to True so the user has access to it.
th,
Jack
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.