Can't .Undo Date control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lyn

    Can't .Undo Date control

    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.


  • Rick Brandt

    #2
    Re: Can't .Undo Date control

    "Lyn" <lhancock@ihug. com.au> wrote in message
    news:cenceb$2fk $1@lust.ihug.co .nz...[color=blue]
    > 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,[/color]
    any[color=blue]
    > data entered into the StartDate control is immediately validated. If the
    > data entered is considered valid, focus moves to the next control in the[/color]
    tab[color=blue]
    > sequence. So far, so good.[snip][/color]

    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




    Comment

    • Lyn

      #3
      Re: Can't .Undo Date control

      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" <lhancock@ihug. com.au> wrote in message
      news:cenceb$2fk $1@lust.ihug.co .nz...[color=blue]
      > 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[/color]
      tab[color=blue]
      > sequence. So far, so good.
      >
      > If the data entered in StartDate is considered invalid, an error message[/color]
      is[color=blue]
      > displayed via MsgBox. When OK is clicked, the statement[/color]
      "Me!StartDate.U ndo"[color=blue]
      > 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[/color]
      correction.[color=blue]
      > 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[/color]
      completely[color=blue]
      > before validation occurs, so OnChange is not suitable -- even though it[/color]
      does[color=blue]
      > 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[/color]
      SetFocus[color=blue]
      > method. (BeforeUpdate event occurs before the database is updated.)
      >
      > 3) AfterUpdate:
      > This event behaves basically the same as in the BeforeUpdate event[/color]
      (without[color=blue]
      > 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[/color]
      to[color=blue]
      > the StartDate field, I have found that I can do two SetFocus statements,[/color]
      the[color=blue]
      > 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[/color]
      SetFocus[color=blue]
      > 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[/color]
      me.[color=blue]
      > Am I coding the Undo incorrectly?
      >
      > Any help appreciated. TIA.
      >
      > --
      > Cheers,
      > Lyn.
      >
      >[/color]


      Comment

      Working...