Thanks for replying, I have done this already with no luck. Let me explain.
I have a command button in a sub form to add new record. The button uses the
following code:
DoCmd.GoToRecord , , acNewRec
Me("ProgressNotesDate").SetFocus
I do not want the user to leave the "ProgressNotesDate" without entering a
date if all of the controls on the subform have no data, however, I want to
enable the user to exit and undo the record, if he clicked add new record by
mistak. Me.undo is not achieving this. I placed the following code in the
ProgressNotesDate_on exit:
************************
Dim ctl As Control, frm As Form, strDataEntered As String
For Each ctl In Me.Controls
With ctl
Select Case .ControlType
Case 109, 111
strDataEntered = Nz(Len(strDataEntered + ctl))
End Select
End With
Next ctl
If Len(strDataEntered) > 0 And IsNull(Me("ProgressNotesDate")) Then
msgbox "You Must Enter Progress Note Date"
Cancel = True
Else
Me.Undo
End If
Set ctl = Nothing
Set frm = Nothing
*****************************************
One other problem I got with placing this code in the onExit event is that I
noticed the it fires as soon as the user clicks the add new record command
button even though the user did not try to exit the progressnotesdate field
yet?