Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2004
    Posts
    59

    Unanswered: On "Enter" key + shortcut keys

    Hi Everyone -

    I know that you can use the "On Enter" property (like the Click function), to run a script when the user enters an item. For example: if I set a textbox to clear when the user enters the textbox I could use something like:

    Sub Function txtTextBox_OnEnter()
    txtTextBox.Text = ""
    End Function

    (not quite sure of the correct wording of the above statement and/or the syntax, but I think you more novice VBers will get the idea)...

    My question is... can you setup a textbox to run something when the <Enter> key is pressed? I would like the user to have a choice, they can either click the "go" command button, or if they enter the info. in the textbox and press "enter" it will do the same thing.

    I know that I can just "CALL CMDButtonGO_Click", but how do I get VB to recognize the Enter key to fire off that call record?

    Does this inquiry make sense? If not, I'll try to clarify... Thanks again everyone for all the help. . . I would be nowhere without it.
    -Matt H-
    www.comperfection.com

  2. #2
    Join Date
    Feb 2004
    Location
    Jaipur, India
    Posts
    40

    Thumbs up Check Ascii Value of Enter Key

    Just check in the KeyPress event of the TextBox whether the enter Key had been pressed or not.....

    Private sub Text1_KeyPress(KeyAscii as Integer)
    If KeyAscii = 13 then
    Call cmdButton_Click()
    End If
    End Sub
    Hope this will Help.
    RGDS
    Amit

  3. #3
    Join Date
    Jul 2004
    Posts
    69
    Maybe it's much more convenient if you code it under the KeyDown event. (This is the way I code) but in either way, it should work.

    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
    'your code place here
    EndIf
    End Sub

  4. #4
    Join Date
    Feb 2004
    Posts
    59

    solved

    thank you all!

    I've got exactly what I was looking for! You all work wonders for a newbie like me!
    -Matt H-
    www.comperfection.com

  5. #5
    Join Date
    Feb 2004
    Posts
    59

    Access 2003 and "On Enter"

    I'm creating a new program, now using Access 2003. I've noticed that they've added a "On Enter" property to the textboxes which has options of "default" and "new line". My code no longer works. Is there new code for VBA for Access 2003?

    Thanks!
    -Matt H-
    www.comperfection.com

  6. #6
    Join Date
    Feb 2004
    Posts
    59
    Okay - Apparently, the "default" setting for the "Enter Key Behavior" field now moves you to the next item in the tab order... by setting this to "New Field In Line" my code now runs properly...

    Just thought i'd re-post in case anyone else is having a similar experience.
    -Matt H-
    www.comperfection.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •