PDA

Click to See Complete Forum and Search --> : Tab Key


SteveCRM
Jan 5th, 2000, 05:45 AM
How do I impliment the tab key with a text box without it moving to another control?

Steve

Gimpster
Jan 5th, 2000, 07:40 AM
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

SteveCRM
Jan 5th, 2000, 07:42 AM
Yes, that's exactly what i mean!

Steve

XxEvilxX
Jan 5th, 2000, 07:43 AM
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

Gimpster
Jan 5th, 2000, 07:47 AM
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:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then
KeyAscii = 0
Text1.Text = Text1.Text & " "
End If
End Sub

That should work for you.

------------------
Ryan

SteveCRM
Jan 5th, 2000, 07:49 AM
for some reason it won't work

Clunietp
Jan 5th, 2000, 01:10 PM
Make sure your text box is set to MULTILINE = TRUE, and add this code:

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


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 butt

SteveCRM
Jan 6th, 2000, 04:18 AM
I get an error here
Controls(I).TabStop = False


Steve

LG
Jan 6th, 2000, 06:07 AM
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).]

SteveCRM
Jan 6th, 2000, 06:39 AM
It still won't work! What's Wrong?

Steve

badgers
Jan 6th, 2000, 06:51 AM
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).]

badgers
Jan 6th, 2000, 07:24 AM
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

Clunietp
Jan 6th, 2000, 10:04 AM
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).]

SteveCRM
Jan 6th, 2000, 11:05 AM
Hey! It worked! I did have a common dialog box on my form. Now is there a way to make it move text?

Steve

Gimpster
Jan 7th, 2000, 01:41 AM
Yup, you can make it move text, and here's the code to do it.

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

Enjoy!

------------------
Ryan