How to avoid Error 2115

AlanS

Registered User.
Local time
Yesterday, 19:18
Joined
Mar 23, 2001
Messages
292
I need some suggestions for avoiding the dreaded 2115 Error. I have a form text box bound to a date/time field in an Access 97 table. All along, I've been using the BeforeUpdate event to ensure that the time entered in the text box is not earlier than the time entered in a previous text box - if it is, a MsgBox is displayed and the event is cancelled. By itself, this approach works fine.

However, I also need to account for the fact that users may enter times either with or without an AM/PM indicator ("a", "am", "p" or "pm"). When the user does not specify such an indicator, Access assumes that the time is AM. So, if the previous text box contains 2:30 PM, and the user enters "3:00" in the subsequent text box, it is taken as 3:00 AM and the validation rule coded into the BeforeUpdate event procedure prevents the update. I've devised a means to determine whether AM or PM is appropriate (if the user does not specify), but when I attempt to use the BeforeUpdate event procedure to add "am" or "pm" to what the user typed, I get the 2115 error. I need to make this adjustment PRIOR to determining whether or not the subsequent text box contains a time value earlier than the prior text box.

I know I can accomplish all this with unbound text boxes, but that requires quite a bit of coding, and I feel there must be a better way. Does anyone know what it might be?
 
For numerous reasons I suggest that you force the users to key a valid time by using a custom Input Mask for that text box.

00:00\ >LL;0;_

That should do it.

Check the help files for the InputMask Property for more info and examples.

HTH
 
Why not just Undo the textbox and force users to enter the correct time
 
Thanks, Rich and ghudson:

I neglected to mention that part of my purpose now is to avoid requiring the users to enter "am" or "pm" when I already have logic that can derive that. Apparently, the way Microsoft has ordered their events makes this difficult or impossible to do.
 

Users who are viewing this thread

Back
Top Bottom