How do I impliment the tab key with a text box without it moving to another control?
Steve
Printable View
How do I impliment the tab key with a text box without it moving to another control?
Steve
Do you mean, how do you make it so that you can enter a 'tab' in a text box, instead of moving to another object? Is that what you mean?
------------------
Ryan
Yes, that's exactly what i mean!
Steve
well here a code i wrote but it not working why
Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
Dim A
Dim B
A = RichTextBox1.Text
B = vbspace & vbspace & vbspace & vbspace
If keyacsii = vbKeyTab Then
A = A & B
End If
End Sub
The reason it's not working is because you need to assign A back to the text of the text box. But you can do this:
That should work for you.Code:Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then
KeyAscii = 0
Text1.Text = Text1.Text & " "
End If
End Sub
------------------
Ryan
for some reason it won't work
Make sure your text box is set to MULTILINE = TRUE, and add this code:
you wouldn't think it was this complicated to get a tab in a textbox, but I would LOVE to see a better way, cuz this is a pain in the buttCode:Private Sub Text1_GotFocus()
Dim I As Long
For I = 0 To Controls.Count - 1 ' Use the Controls collection
Controls(I).TabStop = False
Next I
End Sub
Private Sub Text1_LostFocus()
Dim I As Long
For I = 0 To Controls.Count - 1
Controls(I).TabStop = True
Next
End Sub
I get an error here
Controls(I).TabStop = False
Steve
The Rayn's code work, you just cannot see it because cursor jumps on the first position of the text box.
You have to add a line:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then
KeyAscii = 0
Text1.Text = Text1.Text & " "
' This line
Text1.SelStart = Len(Text1)
End If
End Sub
[This message has been edited by LG (edited 01-06-2000).]
It still won't work! What's Wrong?
Steve
never mind I didn't read the responses just the question! :o
the gotfocus lost focus works for me
[This message has been edited by badgers (edited 01-06-2000).]
I just tried the got and lost focus code that Clunietp posted, with a common dialog control on the form and it stoped working. I am guessing that it is because that control does not have a tab stop property. Is it possible to check first before trying to set it?
I don't think on error resume next is a good way
Sorry, I forgot to add
On Error Resume Next
Some controls do not have a tabstop property, and that is why you get an error. Just add the above statement at the beginning of the sub. It doesn't matter that you use ON ERROR RESUME NEXT if this is the only code in your GotFocus event, otherwise add ON ERROR GOTO 0 after the for each...next loop
Tom
[This message has been edited by Clunietp (edited 01-06-2000).]
Hey! It worked! I did have a common dialog box on my form. Now is there a way to make it move text?
Steve
Yup, you can make it move text, and here's the code to do it.
Enjoy!Code:Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then
Dim x As Integer
Dim text As String
KeyAscii = 0
text = Text1.text
x = Text1.SelStart
Text1.text = Mid(text, 1, x) & " " & Mid(text, x + 1, Len(text) - x)
Text1.SelStart = x + 4
End If
End Sub
------------------
Ryan