if statement

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

Douglas J. Steele

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
 
S

Sarah at DaVita

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
 
S

Sarah at DaVita

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

mcescher

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

Rastro

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
 

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

Similar Threads


Top