VB6 Enter button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wernerh
    New Member
    • Jul 2007
    • 104

    VB6 Enter button

    Hi, I have tried to find literature and web search pertaining to this subject with no luck, maybe someone can tell me if it is possible or not. My app is finance based and for obvious reasons has many numeric text fields on the forms. The natural instinct when the user fills in the last field is to press "Enter" on the keyboard. At the moment i have butons that say calculate to execute the script. Is there any way to have the last text box on a form execute a certain script when enter is pressed after data is captured in that field? Thanks
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    On the click event of the button you want to execute the code, make that button default button by setting the Default property of the button to True.
    Last edited by Killer42; Nov 29 '07, 11:06 PM.

    Comment

    • Wernerh
      New Member
      • Jul 2007
      • 104

      #3
      Originally posted by debasisdas
      On the click event of the button you want to execute the code ,make that buton default button by setting the default property of the button to TRUE.
      The button works fine - the click event is operational. I am asking about the "enter" button on your keyboard that will execute a code. In other words the application links to the enter button on your keyboard? Does this make sense?

      Comment

      • Wernerh
        New Member
        • Jul 2007
        • 104

        #4
        Originally posted by Wernerh
        The button works fine - the click event is operational. I am asking about the "enter" button on your keyboard that will execute a code. In other words the application links to the enter button on your keyboard? Does this make sense?
        Ok, sorry see what you meanI Can the same be done for a text box as there is no default setting?

        Comment

        • hariharanmca
          Top Contributor
          • Dec 2006
          • 1977

          #5
          Originally posted by Wernerh
          Ok, sorry see what you meanI Can the same be done for a text box as there is no default setting?
          Try this in textbox keypress event,

          [CODE=vb]If keyAscii = 13 then cmdName_Click()[/CODE]

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            For textbox you need to handle key strokes .

            Comment

            • Mohan Krishna
              New Member
              • Oct 2007
              • 115

              #7
              Hi Wernerh!

              May this help u along with the above two explained u
              Code:
              Private Sub Text1_KeyPress(KeyAscii As Integer)
                  If KeyAscii = 13 Then Text2.SetFocus
              End Sub
              
              Private Sub Text2_KeyPress(KeyAscii As Integer)
                  If KeyAscii = 13 Then Text3.SetFocus
              End Sub
              Better u take texts array and use...
              Code:
              Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
                  If Index <> Text1.Count - 1 Then
                      If KeyAscii = 13 Then Text1(Index + 1).SetFocus
                  Else
                      'create your command
                      MsgBox "Hi"
                  End If
              End Sub
              RESPOND whether I got ur point...
              ALL THE BEST!

              Comment

              • captainphoenix
                New Member
                • Mar 2007
                • 22

                #8
                Originally posted by Mohan Krishna
                Hi Wernerh!

                May this help u along with the above two explained u
                Code:
                Private Sub Text1_KeyPress(KeyAscii As Integer)
                    If KeyAscii = 13 Then Text2.SetFocus
                End Sub
                
                Private Sub Text2_KeyPress(KeyAscii As Integer)
                    If KeyAscii = 13 Then Text3.SetFocus
                End Sub
                Better u take texts array and use...
                Code:
                Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
                    If Index <> Text1.Count - 1 Then
                        If KeyAscii = 13 Then Text1(Index + 1).SetFocus
                    Else
                        'create your command
                        MsgBox "Hi"
                    End If
                End Sub
                RESPOND whether I got ur point...
                ALL THE BEST!
                does vb6 have an "Accept Button" property under the form's properties window?

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Originally posted by captainphoenix
                  does vb6 have an "Accept Button" property under the form's properties window?
                  If I understand the question properly, I think the KeyPreview property is what you're after. However, it may depend on what version of VB you're using.

                  Comment

                  • 9815402440
                    New Member
                    • Oct 2007
                    • 180

                    #10
                    hi
                    following lines may help you.

                    set the KeyPreview property of the Form to True either in properties window or by typeing Keypreview = true in form_load event.

                    in the form_keydown event write following code

                    if keycode = vbkeyreturn then
                    if me.activecontor l.name = "textbox name" then ''use this line if neccessary
                    run script
                    endif
                    endif

                    you can also check the type of the active control as

                    if typeof me.activecontro l is textbox then
                    do something
                    endif



                    regards
                    manpreet singh dhillon hoshiarpur

                    Comment

                    • Killer42
                      Recognized Expert Expert
                      • Oct 2006
                      • 8429

                      #11
                      Was this any help?

                      Comment

                      Working...