{ENTER} in textbox

Discussion in 'AutoCAD' started by Matt W, Sep 21, 2004.

  1. Matt W

    Matt W Guest

    It doesn't appear that it's possible to run a command simply by pressing
    ENTER while in a textbox.
    What I'd like to be able to do is let the user type something in a textbox
    then press ENTER and then have the app run a command but I can't seem to
    find any way to do this.

    Every time I press ENTER, it jumps to the next control on the form based on
    the TabIndex number.

    TIA
     
    Matt W, Sep 21, 2004
    #1
  2. Matt W

    Jeff Mishler Guest

    How about something like this?

    Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
    Shift As Integer)
    'Catch "enter" & spacebar keys
    If (KeyCode = 13) Or (KeyCode = 32) Then
    OKButton_Click
    End If
    End Sub
     
    Jeff Mishler, Sep 21, 2004
    #2
  3. Matt W

    Matt W Guest

    Ahhhh... yeah. That'll work.
    Must've been having one of those mental blocks. ;)

    Thanks!

    --
    I love deadlines
    I like the whooshing sound they make as they fly by.

    | How about something like this?
    |
    | Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
    | Shift As Integer)
    | 'Catch "enter" & spacebar keys
    | If (KeyCode = 13) Or (KeyCode = 32) Then
    | OKButton_Click
    | End If
    | End Sub
    |
    | --
    | Jeff
    | check out www.cadvault.com
    | | > It doesn't appear that it's possible to run a command simply by pressing
    | > ENTER while in a textbox.
    | > What I'd like to be able to do is let the user type something in a
    textbox
    | > then press ENTER and then have the app run a command but I can't seem to
    | > find any way to do this.
    | >
    | > Every time I press ENTER, it jumps to the next control on the form based
    | > on
    | > the TabIndex number.
    | >
    | > TIA
    | >
    | > --
    | > I love deadlines
    | > I like the whooshing sound they make as they fly by.
    | >
    | >
    | >
    |
    |
     
    Matt W, Sep 21, 2004
    #3
  4. How about having a command button defined as default ? Pressing Enter would
    trigger it...

    Gilles
     
    Gilles Plante, Sep 23, 2004
    #4
  5. And how do you do that?

    --

    Thanks,

    David M. Gardner
    Change the DOT to reply.
     
    David M. Gardner, Sep 23, 2004
    #5
  6. 1- Add a command button to the dialog

    2- Write the code you need to execute in the Click event for this button.
    The code will get the content of the text box

    3- Set the "Default" property for the command button to True

    4- Enjoy ! Type anything in the text box and hit enter. It is the same as if
    you would click the button.

    Here is the code I used to test:

    Private Sub cmbGO_Click()

    MsgBox "You typed: " & Me.tbText.Text, vbOKOnly, "Message"

    End Sub

    The command button was named cmbGO, and the text box tbText

    Gilles
     
    Gilles Plante, Sep 23, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.