By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,988 Members | 1,476 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,988 IT Pros & Developers. It's quick & easy.

VB6 Enter button

100+
P: 104
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
Nov 29 '07 #1
Share this Question
Share on Google+
10 Replies


debasisdas
Expert 5K+
P: 8,127
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.
Nov 29 '07 #2

100+
P: 104
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?
Nov 29 '07 #3

100+
P: 104
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?
Nov 29 '07 #4

hariharanmca
100+
P: 1,977
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,

Expand|Select|Wrap|Line Numbers
  1. If keyAscii = 13 then cmdName_Click()
Nov 29 '07 #5

debasisdas
Expert 5K+
P: 8,127
For textbox you need to handle key strokes .
Nov 29 '07 #6

Mohan Krishna
100+
P: 115
Hi Wernerh!

May this help u along with the above two explained u
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text1_KeyPress(KeyAscii As Integer)
  2.     If KeyAscii = 13 Then Text2.SetFocus
  3. End Sub
  4.  
  5. Private Sub Text2_KeyPress(KeyAscii As Integer)
  6.     If KeyAscii = 13 Then Text3.SetFocus
  7. End Sub
  8.  
Better u take texts array and use...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
  2.     If Index <> Text1.Count - 1 Then
  3.         If KeyAscii = 13 Then Text1(Index + 1).SetFocus
  4.     Else
  5.         'create your command
  6.         MsgBox "Hi"
  7.     End If
  8. End Sub
  9.  
RESPOND whether I got ur point...
ALL THE BEST!
Nov 29 '07 #7

P: 22
Hi Wernerh!

May this help u along with the above two explained u
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text1_KeyPress(KeyAscii As Integer)
  2.     If KeyAscii = 13 Then Text2.SetFocus
  3. End Sub
  4.  
  5. Private Sub Text2_KeyPress(KeyAscii As Integer)
  6.     If KeyAscii = 13 Then Text3.SetFocus
  7. End Sub
  8.  
Better u take texts array and use...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
  2.     If Index <> Text1.Count - 1 Then
  3.         If KeyAscii = 13 Then Text1(Index + 1).SetFocus
  4.     Else
  5.         'create your command
  6.         MsgBox "Hi"
  7.     End If
  8. End Sub
  9.  
RESPOND whether I got ur point...
ALL THE BEST!
does vb6 have an "Accept Button" property under the form's properties window?
Nov 29 '07 #8

Expert 5K+
P: 8,434
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.
Nov 29 '07 #9

9815402440
100+
P: 180
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.activecontorl.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.activecontrol is textbox then
do something
endif



regards
manpreet singh dhillon hoshiarpur
Nov 30 '07 #10

Expert 5K+
P: 8,434
Was this any help?
Dec 12 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.