|
-
Aug 19th, 2002, 01:16 AM
#1
Thread Starter
Lively Member
Enter key in Text Box Tabs to next field
Hi,
I am having a very strange problem.
I have a text box which the user can type data into. Recently, when the Enter key is pressed, instead of adding a new line in the text box, it Tabs to the next field.
I retried an old version (from SourceSafe) and the Enter key worked fine - yet I can't see any differences to the property of the Text box.
I also have the following event which is called for a normal keypress but not the enter key
Code:
Private Sub txtEmail_KeyPress(KeyAscii As MSForms.ReturnInteger)
I have seen several other threads with similar problems - could this be a VB6 problem???
Thanks,
Tim
-
Aug 19th, 2002, 01:32 AM
#2
Fanatic Member
Do you mean that u need to make the enter key to be functioned as tabs to next object ???
if so, can use keycode events, or keypress :
if you use keycode :
Code:
Private Sub txtEmail_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyReturn
'your code goes here
End Select
End Sub
or if you use keypress :
Code:
Private Sub txtEmail_KeyPress(KeyAscii As Integer)
if KeyAscii = 13 Then
'your code goes here
End If
End Sub
I only use the code when the textbox is single line. If I need to use it as multiline, I can't use the code above, since I need the return key to make a new line at the textbox.
Is it help ???
___________
Wille
-
Aug 19th, 2002, 01:37 AM
#3
Thread Starter
Lively Member
No, the opposite.
The Enter Key is Tabbing to the next field, when I want a carriage added to the text and focus to stay on the text box.
The Key pressed event is not firing for the enter key (but it does for any other key).
-
Aug 19th, 2002, 02:22 AM
#4
Fanatic Member
do u mind to post the code here ?
-
Aug 19th, 2002, 02:29 AM
#5
Thread Starter
Lively Member
There's not much Code as such .. this has been taken from the Text box properties ..
Code:
Begin MSForms.TextBox txtEmail
Height = 1215
Left = 120
TabIndex = 4
Top = 840
Width = 9015
VariousPropertyBits= -1400879077
ScrollBars = 2
Size = "15901;2143"
FontName = "@MingLiU"
FontHeight = 165
FontCharSet = 0
FontPitchAndFamily= 34
End
No event is firing when the enter key is pressed! (Except for the key up event on the control that is given focus) ...
-
Aug 19th, 2002, 02:38 AM
#6
Thread Starter
Lively Member
This must be a common enough problem - I've found quite a few references to it by searching (but no obvious solutions)
http://www.vbforums.com/showthread.p...tBox+Enter+Key
-
Aug 19th, 2002, 02:57 AM
#7
Fanatic Member
Originally posted by tgoodmannz
No event is firing when the enter key is pressed! (Except for the key up event on the control that is given focus) ...
Yupe... There will be no event fired, if u not set anycode for it.
For multi line textbox object and Keypreview properties of the form is set to false, return key is functioned to make a new line in that multiline textbox object.
If you add the code like the URL u gave us here, it will make the return key set as TABS key.
____________
Wille
-
Aug 19th, 2002, 05:05 AM
#8
Thread Starter
Lively Member
I regret that we are going around in circles somewhat.
Pressing the enter key does not execute code for an EnterKeys event.
What I want: a carriage return to be added to the Text within the text box.
What happens: Another control is given focus.
Please have a look at the reference in the previous post - If I press CTRL+ENTER then a carriage return is written
Cheers,
Tim
-
Aug 21st, 2002, 05:38 PM
#9
Thread Starter
Lively Member
Resolution!
OK - I forgot I was actually using the Forms 2.0 text box.
Once I set the property
Code:
EnterKeyBehaviour = True
it started working ..
However there was still some wierd behaviour - for some reason adding or removing a line did not refresh the displayed text properly - to fix that I added the following code
Code:
Private Sub txt1_Keyup(KeyCode As MSForms.ReturnInteger, Shift As Integer)
Select Case KeyCode
Case vbKeyReturn, vbKeyBack, vbKeyDelete
txt1.SelLength = 3
txt1.SelLength = 0
End Select
End Sub
Enjoy!
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
|