Set Focus Problem

C

Chris

In the following code I have 3 IF Statements. The first IF
sets the focus to the Client Field and works fine. The
second and third IF Statements move to the next field when
it should set the Focus back on itself. Any suggestions?

Private Sub Loan_Number_LostFocus()
If (IsNull([Client] = True)) Then
MsgBox ("You are required to input a Client number
first")
[Forms]![frmMain].[Client].SetFocus
End If




If ([Forms]![frmMain].[Client] = "708") Then
If Len([Loan_Number] <> 10) Then
MsgBox ("You must supply a 10 digit Loan Number for
708 Loan")
[Forms]![frmMain].[Loan_Number].SetFocus
End If
End If



If ([Forms]![frmMain].[Client] <> "708") Then
If Len([Loan_Number] <> 7) Then
MsgBox ("You must supply a 7 digit Loan Number for
this Client")
[Forms]![frmMain].[Loan_Number].SetFocus
End If
End If

End Sub
 
W

Wayne Morgan

Try the check in the Exit event instead. You can then set Cancel=True to
cancel leaving the control.
 
R

Rick B

I have had similar problems in the past. I believe it has something to do
with the fact that the "lost focus" code runs just *before* the focus is
actually lost. After the code runs, then the focus is lost. I have seen it
explained before and it made sense.

I was able to move my code to a "before update" type of routine and
everything worked well.

In one case (as hokey as it may seem) I set the focus to the prior field and
then sent a tab.

Not sure is that will help in your instance.


Rick B

In the following code I have 3 IF Statements. The first IF
sets the focus to the Client Field and works fine. The
second and third IF Statements move to the next field when
it should set the Focus back on itself. Any suggestions?

Private Sub Loan_Number_LostFocus()
If (IsNull([Client] = True)) Then
MsgBox ("You are required to input a Client number
first")
[Forms]![frmMain].[Client].SetFocus
End If




If ([Forms]![frmMain].[Client] = "708") Then
If Len([Loan_Number] <> 10) Then
MsgBox ("You must supply a 10 digit Loan Number for
708 Loan")
[Forms]![frmMain].[Loan_Number].SetFocus
End If
End If



If ([Forms]![frmMain].[Client] <> "708") Then
If Len([Loan_Number] <> 7) Then
MsgBox ("You must supply a 7 digit Loan Number for
this Client")
[Forms]![frmMain].[Loan_Number].SetFocus
End If
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

Top