Exit event vs another?

  • Thread starter Thread starter Joe Holzhauer
  • Start date Start date
J

Joe Holzhauer

I have a continuous subform that is for entering estimates. In order to
streamline the process, I want to populate a description field when the user
tabs out of an ID field. I don't want the user to be able to leave the ID
field blank, so I check for this in the Exit event code. The problem is
that when I close the form, it still runs the Exit code and up pops my
window saying "Please enter a valid ID!" Is there a way around this?
 
There is no guarantee that the user will ever visit the ID field, so the
only way to be sure it has a value is to use the BeforeUpdate event of the
*form* to test if it IsNull().

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.ID) Then
Cancel = True
MsgBox "Fill in the ID, or press <Esc> to undo."
Me.ID.SetFocus.
End If
End Sub

That approach will not give the problem on a new row where nothing is
entered, since no update is taking place.
 
Thank you, thank you, thank you!

Allen Browne said:
There is no guarantee that the user will ever visit the ID field, so the
only way to be sure it has a value is to use the BeforeUpdate event of the
*form* to test if it IsNull().

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.ID) Then
Cancel = True
MsgBox "Fill in the ID, or press <Esc> to undo."
Me.ID.SetFocus.
End If
End Sub

That approach will not give the problem on a new row where nothing is
entered, since no update is taking place.
 
Back
Top