Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2003
    Location
    London, Gtr London, England
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Undoing a Field (2002 (10.6501.6817) sp3)

    Hi there,

    I'm having a problems re undoing data entered into a date field. I'm using the before update on the field itself in order to undo any dates entered that are greater than the current date. This works fine for manually entered dates. I've also given users the facility of being able to double-click on the date field in order to bring up the calendar control (MSCAL.Calendar.7) and then select a date without having to type. This is where my "me.field.undo" is failing if the date selected is invalid. Effectively nothing happens until the user tries to move to the next record.

    In the manually entered instance, moving out of the field brings up the error message and upon clicking "OK" returns the focus to the field and resets the value to the original.

    The calendar instance doesn't throw up the message until the user tries to move to the next record. Moving out of the field does not trigger the fields before update event. When trying to move to the next record, the error message from the forms before update event is displayed and clicking on "OK" returns the focus to the field, but does not reset the date back to the original. Pressing the escape key will do this, but what else do I need to do in the VBA side in order to make this an automatic process as occurs for the manual entry method? Can someone also advise me as to what is different between the manual and calendar entry methods?

    The attached DB highlights the above problem.

    Cheers,

    Niven
    Attached Files Attached Files

  2. #2
    3 Star Lounger
    Join Date
    Nov 2003
    Location
    London, Gtr London, England
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Undoing a Field (2002 (10.6501.6817) sp3)

    I have sussed a work around here that places the test for the date selected, in the calendar's "objCalendar_DblClick()" event. This has the effect that the user can't select a date greater than current from the calendar itself. The code is as follows:

    Private Sub objCalendar_DblClick()
    Dim ctl As Control
    Set ctl = Me!objCalendar

    If ctl.Value > Date Then

    MsgBox "Date selected cannot be greater than today. " & _
    vbCr & vbCr & _
    " Please select another Date.", vbExclamation

    Else

    datCalDate = ctl.Value
    DoCmd.Close


    End If

    End Sub

    Whilst this has taken away the problem of the "poked in" calendar date skipping the "dteDateObserved" field's "before update" event, I would still be most grateful to know why this occurs.

    Cheers,

    Niven

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Undoing a Field (2002 (10.6501.6817) sp3)

    The Before Update event of a control only occurs if the user edits its value, not if the value is set by Visual Basic code.
    This is intentional, for if the Before Update event would occur when the value is changed by Visual Basic code in the After Update event, you'd get stuck in an endless loop of Before Update and After Update events.
    So it is the responsibility of the programmer to check values before setting them in code - precisely what you are doing as workaround!

  4. #4
    3 Star Lounger
    Join Date
    Nov 2003
    Location
    London, Gtr London, England
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Undoing a Field (2002 (10.6501.6817) sp3)

    Ah Ha!

    Puzzled over that for quite a while this morning, indeed most of it!

    Cheers,

    Niven

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •