how to use a textbox and hit enter to make it click a button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • negus
    New Member
    • Jan 2010
    • 18

    how to use a textbox and hit enter to make it click a button

    so basically i have a textbox and i need to be able to hit the enter key and have it click a button

    its for my web browser project im doing for a final and cant seem to figure it out

    i have the textbox for the URL area and a go button.

    thanks for your help in advance!
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    You don't really need to make it click the button.
    The onclick event for the button calls a function that you attach to it when you create the button.

    All you need to do is in the onkeydown event for the textbox is
    check to see if the enter key was pressed
    if yes then call the same function that the buttons onclick calls

    Comment

    • vb5prgrmr
      Recognized Expert Contributor
      • Oct 2009
      • 305

      #3
      Delerna, the onkeydown event is either vba or .net as I know it is not a VB6 event...
      Code:
      Option Explicit
      
      Private Sub Command1_Click()
      MsgBox "clicked"
      End Sub
      
      Private Sub Text1_KeyPress(KeyAscii As Integer)
      If KeyAscii = vbKeyReturn Then Command1.Value = True
      End Sub

      Good Luck

      Comment

      • Delerna
        Recognized Expert Top Contributor
        • Jan 2008
        • 1134

        #4
        Delerna, the onkeydown event is either vba or .net as I know it is not a VB6 event
        That is true in the syntactical sense. I was refering to the event that occurs when you press a key down or click a button, thats why there was no code. I guess I should have written "the click event" rather than "onclick event" and "the key down event" rather than "onkeydown event" so I concede your point. I suppose the way I wrote them reflects where I do most of my development these days.

        Whatever the syntax however, the idea still remains the same
        also
        ControlName_Key Down(...) is indeed a valid VB6 event
        as is
        ControlName_Key Up(...)

        Comment

        • negus
          New Member
          • Jan 2010
          • 18

          #5
          Ah i got it, it was in the Form options just had to set the accept button to my go button, but thank you for the help!

          Comment

          Working...