|
-
Jan 5th, 2000, 06:45 AM
#1
Thread Starter
Frenzied Member
How do I impliment the tab key with a text box without it moving to another control?
Steve
-
Jan 5th, 2000, 08:40 AM
#2
Hyperactive Member
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
-
Jan 5th, 2000, 08:42 AM
#3
Thread Starter
Frenzied Member
Yes, that's exactly what i mean!
Steve
-
Jan 5th, 2000, 08:43 AM
#4
Addicted Member
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
-
Jan 5th, 2000, 08:47 AM
#5
Hyperactive Member
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:
Code:
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
-
Jan 5th, 2000, 08:49 AM
#6
Thread Starter
Frenzied Member
for some reason it won't work
-
Jan 5th, 2000, 02:10 PM
#7
Guru
Make sure your text box is set to MULTILINE = TRUE, and add this code:
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
-
Jan 6th, 2000, 05:18 AM
#8
Thread Starter
Frenzied Member
I get an error here
Controls(I).TabStop = False
Steve
-
Jan 6th, 2000, 07:07 AM
#9
Hyperactive Member
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).]
-
Jan 6th, 2000, 07:39 AM
#10
Thread Starter
Frenzied Member
It still won't work! What's Wrong?
Steve
-
Jan 6th, 2000, 07:51 AM
#11
-
Jan 6th, 2000, 08:24 AM
#12
Hyperactive Member
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
-
Jan 6th, 2000, 11:04 AM
#13
Guru
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).]
-
Jan 6th, 2000, 12:05 PM
#14
Thread Starter
Frenzied Member
Hey! It worked! I did have a common dialog box on my form. Now is there a way to make it move text?
Steve
-
Jan 7th, 2000, 02:41 AM
#15
Hyperactive Member
Yup, you can make it move text, and here's the code to do it.
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
Enjoy!
------------------
Ryan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|