468,556 Members | 2,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,556 developers. It's quick & easy.

Can't .Undo Date control

Lyn
Hi,
I have a text control on a form which is bound to table field StartDate
which is in Date format. When updating the table record via the form, any
data entered into the StartDate control is immediately validated. If the
data entered is considered valid, focus moves to the next control in the tab
sequence. So far, so good.

If the data entered in StartDate is considered invalid, an error message is
displayed via MsgBox. When OK is clicked, the statement "Me!StartDate.Undo"
is executed. I was expecting that the original data in this control would
be restored and for focus to remain on that data to allow correction.

However, the actual results depends on which event I use to trigger the
validation, none of which gives the expected results:-

1) OnChange:
This event does correctly undo the StartDate data (restoring the original
value) and that original data is selected (has focus) ready for correction.
However, this event is triggered as soon as I change a single character in
the StartDate. Obviously, I want to be able to set the new date completely
before validation occurs, so OnChange is not suitable -- even though it does
the Undo as I would expect.

2) BeforeUpdate:
This event allows the whole field to be updated and validation does not
occur until focus is moved off the StartDate control (eg, via using tab).
However, after validation the field is NOT undone (despite the Undo method
statement) and focus moves to the next field, allowing the invalid data to
stand. As a workaround, I have tried to force the focus back to the
StartDate field, but this just gives me an error message "Runtime error
'2108'" which states that the field must be saved before using the SetFocus
method. (BeforeUpdate event occurs before the database is updated.)

3) AfterUpdate:
This event behaves basically the same as in the BeforeUpdate event (without
the workaround). When I apply the workaround to force focus back to
StartDate, the focus instead moves to the next control in tab order
(assuming that I have used tab to trigger validation). To get focus back to
the StartDate field, I have found that I can do two SetFocus statements, the
first one being a dummy one to any other control:-

Me!OtherControl.SetFocus
Me!StartDate.SetFocus

However, this just puts the cursor into the first character position of
StartDate rather than selecting the whole field, and it still doesn't Undo
the updated field value. I have tried Undo then SetFocus, and also SetFocus
then Undo -- no difference.

Am I using the wrong trigger event to validate this field? The Help
suggests using BeforeUpdate or OnChange, but neither of these worked for me.
Am I coding the Undo incorrectly?

Any help appreciated. TIA.

--
Cheers,
Lyn.
Nov 13 '05 #1
2 2391
"Lyn" <lh******@ihug.com.au> wrote in message
news:ce**********@lust.ihug.co.nz...
Hi,
I have a text control on a form which is bound to table field StartDate
which is in Date format. When updating the table record via the form, any data entered into the StartDate control is immediately validated. If the
data entered is considered valid, focus moves to the next control in the tab sequence. So far, so good.[snip]


You need to use BeforeUpdate and set the Cancel argument to True when the
validation fails. It is the Cancel that prevents the focus from leaving
the control. Undo is optional, but usually not necessary. Just let the
user see their invalid entry and force them to change it. That is the
behavior you would get from most other validation methods anyway.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


Nov 13 '05 #2
Lyn
Thanks Rick for your response. Setting Cancel was the missing clue.

I found that I did have to set .Undo to make it work the way I wanted. The
difference is that with .Undo not set, the field was undone and the cursor
was positioned at the right end of the data. Setting .Undo also caused the
whole field to be selected for correction. Only a minor difference, but for
me the latter highlights the field that needs correcting more clearly.

But the real solution I was looking for was setting Cancel to True. Thanks
again.

--
Cheers,
Lyn.

"Lyn" <lh******@ihug.com.au> wrote in message
news:ce**********@lust.ihug.co.nz...
Hi,
I have a text control on a form which is bound to table field StartDate
which is in Date format. When updating the table record via the form, any
data entered into the StartDate control is immediately validated. If the
data entered is considered valid, focus moves to the next control in the tab sequence. So far, so good.

If the data entered in StartDate is considered invalid, an error message is displayed via MsgBox. When OK is clicked, the statement "Me!StartDate.Undo" is executed. I was expecting that the original data in this control would
be restored and for focus to remain on that data to allow correction.

However, the actual results depends on which event I use to trigger the
validation, none of which gives the expected results:-

1) OnChange:
This event does correctly undo the StartDate data (restoring the original
value) and that original data is selected (has focus) ready for correction. However, this event is triggered as soon as I change a single character in
the StartDate. Obviously, I want to be able to set the new date completely before validation occurs, so OnChange is not suitable -- even though it does the Undo as I would expect.

2) BeforeUpdate:
This event allows the whole field to be updated and validation does not
occur until focus is moved off the StartDate control (eg, via using tab).
However, after validation the field is NOT undone (despite the Undo method
statement) and focus moves to the next field, allowing the invalid data to
stand. As a workaround, I have tried to force the focus back to the
StartDate field, but this just gives me an error message "Runtime error
'2108'" which states that the field must be saved before using the SetFocus method. (BeforeUpdate event occurs before the database is updated.)

3) AfterUpdate:
This event behaves basically the same as in the BeforeUpdate event (without the workaround). When I apply the workaround to force focus back to
StartDate, the focus instead moves to the next control in tab order
(assuming that I have used tab to trigger validation). To get focus back to the StartDate field, I have found that I can do two SetFocus statements, the first one being a dummy one to any other control:-

Me!OtherControl.SetFocus
Me!StartDate.SetFocus

However, this just puts the cursor into the first character position of
StartDate rather than selecting the whole field, and it still doesn't Undo
the updated field value. I have tried Undo then SetFocus, and also SetFocus then Undo -- no difference.

Am I using the wrong trigger event to validate this field? The Help
suggests using BeforeUpdate or OnChange, but neither of these worked for me. Am I coding the Undo incorrectly?

Any help appreciated. TIA.

--
Cheers,
Lyn.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Laertes | last post: by
11 posts views Thread by Mad Joe | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.