Full Version: How To Bypass Auto Date Validation
UtterAccess Forums > Microsoft® Access > Access Forms
jp0555
iconfused.gif

Hi (again)!

I have spent several hours altering event handling etc and searching the forums but cannot find a solution to the following.

I have a control bound to a date field on a table. I have the date picker feature enabled, no input mask or validation rule.

When I enter incorrect data I get the expected default error message:
"The value you entered isn't valid for the field '|'.@For example, you may have entered text in a numeric field or a number that is greater than the FieldSize setting permits.".

I have a Command Box that carries out an UnDo command, however clicking on the Undo box regenerates the above invalid data message.

I am presuming that the background system is generating this when the date control loses focus. I have checked the boxes On Click event and the code has not started.

I have tried intercepting the error in the Form On Error event and the focus is still on the Date Control. I was hoping to be able to state that if the Undo Control had been pressed to bypass the error however the Undo box is not in focus yet and so I cannot identify what action has triggered the event.

So how do I accomplish an UnDo on the form via a command button without triggering the data warning. Currently I would have to delete the invalid data in the date field prior to using UnDo.

Any advice welcome.

Thank you.
theDBguy
Hi. Just to be clear, were you able to trap the error in the Form's Error event? If so, why can't you take care of it there?
jp0555
Hi,

If I trap it in the forms error event how do I tell whether it is a genuine error generated by data keyed and enter pressed etc for which I require a warning message or whether it is the extraneous error I want to bypass generated when the UnDo button is pressed?

Regards

Jon
theDBguy
Hi Jon. Couldn't you tell by the error number?
jp0555
Hi

I will have to confirm this but I believe it is the same Invalid Data warning message triggered by the Date field losing focus. It looks like error number 32502.

Regards

Jon
theDBguy
Okay, so if the error number is for the date field, then you should be able to handle it, right?
jp0555
Hi,

In response, given that the data error is the same and I don't know how to differentiate between the genuine error and the UnDo generated error then my reply would be no. As focus in both instances is still with date control.

However I am now suspecting my VBA code. The error number being generated is 0 - even though the error description appears to be that for 32502.

I have looked for subs and functions with no end statement but have not found one yet. It may be that in my error handling I am doing something wrong.

Guess I will have to work out how to use the debugger in Access.

Any advice still more than welcome.

Regards

Jon
theDBguy
Hi Jon. I can't give you any specific advice because I can't see what you're doing. In my mind, I don't see any problems with handling the error at the form level and just check where it came from. Then, handle it accordingly. Doesn't the error event fire first before the Click event of the button? If so, then at that point, you can tell that the error came from the date field, can't you?
missinglinq
Every thing else aside, why are you entering dates free-hand instead of using the DatePicker, which eliminates the problem? If you would prefer the calendar to pop up when the Control receives Focus, without the user having to click on it, this bit of code will do that

CODE
Private Sub YourDateField_GotFocus()
  DoCmd.RunCommand acCmdShowDatePicker
End Sub

To have it only pop up, on Focus, if the Textbox is empty

CODE
Private Sub YourDateField_GotFocus()
  If Nz(Me.YourDateField,"") = "" Then
   DoCmd.RunCommand acCmdShowDatePicker
  End If
End Sub

Linq ;0)>
jp0555
Hi theDBGuy,

The scenario I am trying to handle is the following:

Incorrect data entered <tab> or <enter>
System warning message generated about invalid data <ok>
User does not correct data but presses UnDo command button
System warning message generated about invalid data <ok>

The second warning is not required but has been generated in an identical manner to the first one and as it occurs before the UnDo click event I don't know how to differentiate between them.

Of course this may well be due to a VBA error generating a 0 error code. Currently under investigation.

Thank you for all your advice and please keep it coming.
jp0555
Hi missinglinq

The date picker is great as far as it goes especially if you need to enter a date in the current month. If you want to enter a date from last year or the year before it doesn't seem to be so user friendly.
Anyway if there is a data entry field present and the user wants to correct a wrong entry you have to cater for them entering gibberish.
I believe there are other more functional calendars available but my time constraints prevent me from investigating too deeply.

Thanks for the advice.
theDBguy
Hi Jon. Here's what I see (in red below):
QUOTE
Incorrect data entered <tab> or <enter>
System warning message generated about invalid data <ok>
Error event code automatically "undo" the wrong date entered by the user, so they don't have to click on the Undo button
User does not correct data but presses UnDo command button
System warning message generated about invalid data <ok>

Hope that helps...
jp0555
Thanks to everyone who has replied.
As someone who is only six weeks into Access I am still getting my head round the order of event processing.
I should now be able to code a consistent approach in all the forms.

Regards

Jon
theDBguy
Hi Jon. Just let us know if you need more help. Good luck!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.