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.U ndo"
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.Se tFocus
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.
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.U ndo"
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.Se tFocus
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.
Comment