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

handle ctrl+enter

P: 88
hello,

i have a userform in a vba macro which contains three text boxes. sometimes i want to fill in only the first one, and other times one or two of the other as well. when i today want to leave a box empty, i have to press [tab] one or several times to reach the "submit" command button.

is there a way that i could trigger the btnSubmit_Click() event by pressing [Ctrl]+[Enter]? how?
Sep 12 '07 #1
Share this Question
Share on Google+
4 Replies


P: 37
... is there a way that i could trigger the btnSubmit_Click() event by pressing [Ctrl]+[Enter]? how?

Hi,

Check the below code, I think that will answer your question

Expand|Select|Wrap|Line Numbers
  1. Private Sub  btnSubmit_Click() 
  2. MsgBox "Submitted"
  3. End Sub
  4.  
  5. Private Sub Text1_KeyPress(KeyAscii As Integer)
  6. If KeyAscii = 10 Then
  7.   btnSubmit_Click
  8. End If
  9. End Sub
Reply me...
Sep 12 '07 #2

hariharanmca
100+
P: 1,977
... is there a way that i could trigger the btnSubmit_Click() event by pressing [Ctrl]+[Enter]? how?
I think the below link will help you

KeyAscii
Sep 12 '07 #3

P: 88
Hi,

Check the below code, I think that will answer your question

Expand|Select|Wrap|Line Numbers
  1. Private Sub  btnSubmit_Click() 
  2. MsgBox "Submitted"
  3. End Sub
  4.  
  5. Private Sub Text1_KeyPress(KeyAscii As Integer)
  6. If KeyAscii = 10 Then
  7.   btnSubmit_Click
  8. End If
  9. End Sub
Reply me...
thank you! this worked excellently!
Sep 14 '07 #4

P: 88
Hi,

Check the below code, I think that will answer your question

Expand|Select|Wrap|Line Numbers
  1. Private Sub  btnSubmit_Click() 
  2. MsgBox "Submitted"
  3. End Sub
  4.  
  5. Private Sub Text1_KeyPress(KeyAscii As Integer)
  6. If KeyAscii = 10 Then
  7.   btnSubmit_Click
  8. End If
  9. End Sub
Reply me...
this worked, but now i'm building an application with a lot of controls in several forms. is there a way i could get the same results as if i coded a similar procedure for each control, but by just having one sub? that is, a sub that handles keypress events regardless of which control sends the event.
Sep 19 '07 #5

Post your reply

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