Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setfocus problem 1

Status
Not open for further replies.

jpl458

Technical User
Sep 30, 2009
337
US
Using to following code to check the control for 6 characters. if not, then display message and clear the control, and set the focus back to the control. This code is in the Lost Focus event of the control. However, the cursor never goes back to the examined control and remains in the control that is next in the tab sequence on the form. I've tried moving the setfocus after the MsgBox, but to no avail.

'Check for length of 6 Chars
If Len(Card_No) <> 6 Then
Card_No.Value = ""
Me.Card_No.SetFocus
MsgBox "Wrong Number of characters"
Else
End If

Thanks in advance
 
Duane, it worked as usual, but is that a bug or is it supposed to be that way?

Thanks again

jpl
 

Or if you move your code to the OnExit event, you can simply use

Cancel = True

and the focus will remain in the Card_No textbox:
Code:
Private Sub Card_No_Exit(Cancel As Integer)
'Check for length of 6 Chars
    If Len(Card_No) <> 6 Then
    Card_No.Value = ""
    Cancel = True
    MsgBox "Wrong Number of characters"
    Else
    End If
End Sub


The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top