Exit event vs another?

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?
 
A

Allen Browne

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.
 
J

Joe Holzhauer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top