Highlight Text In A Textbox

V

vqthomf

Hi I was wondering if someone can help I am trying to highlight text in a
textbox if the user miss scan an item into a textbox, I am using the code
below but I can't get it to work any help would much apprecated.
Regards
Charles

Private Sub txtVin_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
'
If KeyCode = 13 Then
If Len(txtVin.Value) = 17 Then
Call Vinchk
Else
MsgBox "Sorry there are not enough character,Please re-scan the
Vin."
With txtVin
.SetFocus
.SelStart = 0
.SelLength = Len(.Text) 'I have also tried .TextLength
End With
End If
End If
Call bntEnabled
End Sub
 
R

Rick Rothstein

What does the "Call bntEnabled" statement do? I'm guessing that it is
probably setting focus to another control. You can overcome this problem by
changing the TextBox's HideSelection property to False; then it will still
show the selected text even if some other control has focus.
 
J

Jacob Skaria

Try with the Exit event..

Private Sub txtVin_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(txtVin.Value) = 17 Then
'Call Vinchk
Else
With txtVin
.SelStart = 0
.SelLength = Len(.Text)
End With
MsgBox "Sorry there are not enough character,Please re-scan the Vin."
Cancel = True
End If
'Call bntEnabled
End Sub

If this post helps click Yes
 
V

vqthomf

Thank that worked, I do one other problem when the item is scanned I
sometimes get $/ is there away to check each character to do the same as
below?
 

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