Set.Focus refinement

G

Guest

In a Before Update routine, I check for a null value in a control. If there is a null value, I want the cursor to go back to where it was. As it is now, it continues on to the next tab stop. I've used the Me!Control.SetFocus before, but when it's imbedded within an IF statement, it doesn't work like I want it to. Below is my routine

If IsNull(Me!boxsickbal) The
strMsg = "No Sick Leave Available.
intStyle = vbOKOnl
strTitle = "Leave Balance Check
MsgBox strMsg, intStyle, strTitl
Me!boxLeaveType.SetFocu
End I

I've even tried placing the SetFocus statement after the IF statement. Doesn't work there either

Everything else seems to be working right, just the SetFocus part. What am I Missing here? As usual, thanks in advance for all your help
JM
 
F

fredg

In a Before Update routine, I check for a null value in a control.
If there is a null value, I want the cursor to go back to where it
was. As it is now, it continues on to the next tab stop. I've
used the Me!Control.SetFocus before, but when it's imbedded within
an IF statement, it doesn't work like I want it to. Below is my
routine.

If IsNull(Me!boxsickbal) Then
strMsg = "No Sick Leave Available."
intStyle = vbOKOnly
strTitle = "Leave Balance Check"
MsgBox strMsg, intStyle, strTitle
Me!boxLeaveType.SetFocus End If

I've even tried placing the SetFocus statement after the IF
statement. Doesn't work there either.

Everything else seems to be working right, just the SetFocus part.
What am I Missing here? As usual, thanks in advance for all your
help. JM


In the FORM BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me!BoxSickBal) Then
MsgBox "Leave Balance Check", vbOKOnly, "Leave Balance Check"
Cancel = True
End If
[Me![BoxLeaveType].SetFocus
End Sub
 
S

Steve Schapel

JM,

What is happening is that you are setting the focus to a control that
already has the focus anyway, within an event (Before Update) which
means the focus will move on when the event is finished, which is after
your SetFocus command. Does that make sense? Seems to me what you
really want to do is cancel the update, like this...
If IsNull(Me!boxsickbal) Then
MsgBox "No Sick Leave Available", , "Leave Balance Check"
Cancel = True
End If
 

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