Results 1 to 3 of 3

Thread: [RESOLVED] Making code run when the user hits 'Enter' in a text box

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    55

    Resolved [RESOLVED] Making code run when the user hits 'Enter' in a text box

    Good Morning,

    I want to make some code run when the user hits enter in a text box on my userform.

    I cant use the run on text change thingy because that will make it run every time the form is loaded, and we dont want that.

    So any idea's how, or what the prefix is, to make code run when the user hits the enter key in a certain text box?

    Thankyou for all your help!
    Last edited by Zimpaz; Mar 27th, 2007 at 05:59 AM.

  2. #2
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Making code run when the user hits 'Enter' in a text box

    Code:
    Private Sub Textbox1_KeyPress(KeyAscii As Integer)
        Select Case KeyAscii
            Case 13
                ' do your thing
            Case Else
                'do other thing
        End Select
    End Sub


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    55

    Re: Making code run when the user hits 'Enter' in a text box

    Thanks very much, i worked it out just before you posed that reply!!


    vb Code:
    1. Private Sub txtPA_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    2.  
    3. Dim NewPA As String
    4.  
    5. If KeyCode = vbKeyReturn Then
    6.  
    7.     Call Module2.Update

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