Can't get Undo to work on a changed field

Christine Pearc

Christine
Local time
Today, 21:49
Joined
May 13, 2004
Messages
111
Could someone look at my code and tell me why my “Me.TargetDate.Undo” won’t work?

First, let me say that the TargetDate field has an On-Click event that calls a module written by Allen Browne), which is shown below and works great.

=CalendarFor([TargetDate],"Select a date from the calendar ")

What happens is that the Me.TargetDate.Undo event always keeps the date selected in the calendar.

Based on something I read from Rual Guy on another issue, I’ve used the TargetDate_LostFocus routine to check for some additional data entry errors. I’ve tried moving the code in “Private Sub TargetDate_Exit(Cancel As Integer)” to the LostFocus, but it doesn’t make any difference to the Undo. I’ve also tried “I’ve tried “Private Sub TargetDate_Change(),Me.Undo…” but that doesn’t work either. :confused:

PHP:
Private Sub TargetDate_Enter()

    If Not IsNull(Me.TargetDate) Then
        OldTarget = Me.TargetDate
    End If

End Sub

PHP:
Private Sub TargetDate_Exit(Cancel As Integer)

    If Not IsNull(Me.TargetDate) Then
        If DateDiff("d", Me.DateOpened, Me.TargetDate) < 0 Then
            MsgBox "You have selected a date that is before…bla bla" 
            Me.TargetDate.Undo
            Me.TargetDate.SetFocus
        ElseIf DateDiff("d", Date, Me.TargetDate) < 0 Then
            MsgBox "You have selected a date that is prior to today's date…bla bla"
            Me.TargetDate.Undo
            Me.TargetDate.SetFocus
        ElseIf Weekday(Me.TargetDate) = 1 Or Weekday(Me.TargetDate) = 7 Then
            MsgBox "You have selected a date that falls on a weekend..bla bla"
            Me.TargetDate.Undo
            Me.TargetDate.SetFocus
        End If
    End If
End Sub

Private Sub TargetDate_LostFocus()
    If Me.TargetDate > OldTarget And Me.cboAssignToID <> OldAssignee Then
        MsgBox "The target date can only be changed if …bla bla"
        Me.TargetDate.Undo
        Me.TargetDate.SetFocus
    End If
End Sub

Ever thankful for this forum,
Christine
 
Hi Christine,
If it helps any, Me.ControlName.Undo *only* works on bound controls. Another issue is that setting the focus to a control that already has the focus does not work effectively as you are using it. Setting Cancel = True in those events will hold the focus in the current control.
 

Users who are viewing this thread

Back
Top Bottom