if statement

  • Thread starter Thread starter Sarah at DaVita
  • Start date Start date
S

Sarah at DaVita

I have an if statement in the on exit comand that says if the control is null
to display a message. I am trying to get it to set the focus on the control
but it is not working. The code I am using is below.
Private Sub Combo7_Exit(Cancel As Integer)
If IsNull(Combo7) Then
MsgBox "LE cannot be null. Please enter the LE number."
End If
Me.Combo7.SetFocus
End Sub
If they do not enter a value in combo7 I want the cursor to stay in that
control.
Any help here would be appreciated.
 
The Cancel parameter does just what it implies: it cancels the event, so
that focus doesn't move.

Try:

Private Sub Combo7_Exit(Cancel As Integer)

If IsNull(Combo7) Then
MsgBox "LE cannot be null. Please enter the LE number."
Cancel = True
End If

End Sub
 
duh... thanks.

Douglas J. Steele said:
The Cancel parameter does just what it implies: it cancels the event, so
that focus doesn't move.

Try:

Private Sub Combo7_Exit(Cancel As Integer)

If IsNull(Combo7) Then
MsgBox "LE cannot be null. Please enter the LE number."
Cancel = True
End If

End Sub
 
k - I did that but now it wont let me close the form it I don't enter an LE.
If the user wants to bail out I want them to be able to do so. I tried
putting the le check on the save button so they cannot save it without an le
but that keeps erroring out.
 
k - I did that but now it wont let me close the form it I don't enter an LE.  
If the user wants to bail out I want them to be able to do so.  I tried
putting the le check on the save button so they cannot save it without an le
but that keeps erroring out.







- Show quoted text -

Instead of using the Exit event, try the BeforeUpdate event. Do all
your checking before the record gets updated.

Hope this helps,
Chris M.
 
Indeed. With this code the Combo7 won't update until it will have a non null
value but the user can undo the change with "esc" and close the form, for
example.

Private sub Combo7_BeforeUpdate()
If Isnull(Combo7) then
MsgBox ""LE cannot be null. Please enter the LE number or Esc to exit"
docmd.CancelEvent
End If
End Sub
 
Back
Top