Results 1 to 9 of 9

Thread: Enter key in Text Box Tabs to next field

  1. #1

    Thread Starter
    Lively Member tgoodmannz's Avatar
    Join Date
    Sep 2000
    Location
    Mid On at the Pavillion End
    Posts
    102

    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

  2. #2
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    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

  3. #3

    Thread Starter
    Lively Member tgoodmannz's Avatar
    Join Date
    Sep 2000
    Location
    Mid On at the Pavillion End
    Posts
    102
    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).

  4. #4
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    do u mind to post the code here ?


  5. #5

    Thread Starter
    Lively Member tgoodmannz's Avatar
    Join Date
    Sep 2000
    Location
    Mid On at the Pavillion End
    Posts
    102
    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) ...

  6. #6

    Thread Starter
    Lively Member tgoodmannz's Avatar
    Join Date
    Sep 2000
    Location
    Mid On at the Pavillion End
    Posts
    102
    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

  7. #7
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    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

  8. #8

    Thread Starter
    Lively Member tgoodmannz's Avatar
    Join Date
    Sep 2000
    Location
    Mid On at the Pavillion End
    Posts
    102
    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

  9. #9

    Thread Starter
    Lively Member tgoodmannz's Avatar
    Join Date
    Sep 2000
    Location
    Mid On at the Pavillion End
    Posts
    102

    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
  •  



Click Here to Expand Forum to Full Width