Data Validation / KeyPress Event

jan@BRU

Registered User.
Local time
Today, 10:08
Joined
Jul 18, 2007
Messages
39
Hello folks,

following on to a in issue I had earlier, I am still struggling with my form. Issue is the following. I have a form, where a textbox is linked to a datefield. I want to be able to enter a time into this field both in the hh:nn and alternative also in the hhnn format or be able to enter 09:00 as 9 and that's it. I figured, I had to enter the text, and capture it, before it is actually committed to the value of the underlying control (or something like that) and then manipulate the text input to a correct time format and commit that one to the field then.

Problem is, I don't know, which event to use:

the change event fires for every character entered (I don't want that, I want it to fire after I have entered 0900 completely.
the beforeupdate event might fire before the date is saved to the database. Still, it checks, whether I entered a correct date/time format which '9' for example is not.

So question: which event to use, or alternatively: how to detect in the change event, that the last one I entered indicates, I'm done with the input?

I have thought of an alternative solution, which doesn't work neither..... grrr. since the up/down arrow keys in a continuous form (oh: did I mention, I am in a cont form?) which are doing the same currently as the left/right arrows (i.e. move to the next tab) to increment/decrement a time field by 15 mins, so I dont have to enter time manually... Now, this works, but I can't get rid of the original function of the up/down key (which is to move to the next tab): so triggering the keypress event and checking for code 38/40 (key up/down) it adds 15 mins (wow!). However it then moves on to the next tab (which is not what i want, since I want to add more increments). Well, I thought setfocus back to the control I'm coming from might help. well it doesn't. somehow it doesn't let me set the focus back on the control, from which the event had triggered. Moving it deliberately to another control and then back, doesn't help neither.

Any solution to either or both of the problems?

many thanks

Jan
 
i would use (only!) the before update event

check the format of the field carefully
i would (in fact I do) not accept an input of just 9
i make them put a 4 character time in with or without a colon (so length must be 4 or 5)

if no colon, I check that the field is numeric
if there is a colon, i check that its in position 3, and that its numeric without the colon

i check that the first 2 digits are between 1 and 24
i check that the last two digits are betwwen 0 and 59

then if its not valid, just do this in the controls before update event

msgbox "time format not valid .... etc etc"
cancel = true

and this prevents the data being accepted until they put a valid sdtring in the field

now, all you have to do is change it to a standard format so you can store it - ie consistently either remove the coln, or insert the colon - then EVERY entry is similar
 

Users who are viewing this thread

Back
Top Bottom