|
-
Jul 30th, 2008, 03:55 AM
#1
Thread Starter
Addicted Member
[RESOLVED] How to use keypress in Excel VBA
hi everyone,
I have a problem in using keypress event in excel. i have this code but it doesn't work. What i want to do is after I input a value in the textbox and press then Enter key the Commandbutton2_click will activate. Can anyone help me.
Thanks and Regards,
Kevin
Code:
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 13 Then
CommandButton2_Click
End If
End Sub
-
Jul 30th, 2008, 04:43 AM
#2
Re: How to use keypress in Excel VBA
enterkeys are not trappable in keypress event in msforms2 textboxes, use keydown or keyup event
vb Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
CommandButton1_Click
End If
End Sub
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 30th, 2008, 08:49 AM
#3
Thread Starter
Addicted Member
Re: How to use keypress in Excel VBA
Hi pete,
Your code works!! thanks!! now my only problem is how to trap if the user inputs an incorrect password. im still trying to figure out.
Last edited by allankevin; Jul 30th, 2008 at 08:59 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|