Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I was given the following code for a combobox to have cursor advance to next
field if the ENTER button was pressed. Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then txtQty.SetFocus End Sub However, I am finding out that this does not work for textboxes, since you have to type (keydown) in a textbox vs choosing from a list. I want the cursor to advance to the next textbox, and have the backcolor turn yellow to show current field. How does the PRIVATE Sub need to read since KEYDOWN is not appropriate? Private Sub Textbox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then textbox2.SetFocus Textbox2.Backcolor = vbYellow End Sub Thanks, Les |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try using the TextBox's KeyPress event instead of its KeyDown event.
Rick "WLMPilot" wrote in message ... I was given the following code for a combobox to have cursor advance to next field if the ENTER button was pressed. Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then txtQty.SetFocus End Sub However, I am finding out that this does not work for textboxes, since you have to type (keydown) in a textbox vs choosing from a list. I want the cursor to advance to the next textbox, and have the backcolor turn yellow to show current field. How does the PRIVATE Sub need to read since KEYDOWN is not appropriate? Private Sub Textbox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then textbox2.SetFocus Textbox2.Backcolor = vbYellow End Sub Thanks, Les |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Did not work. Did the same thing. What is the difference between KeyDown
and KeyPress? Sounds like they both check for the same thing. Any other ideas that will capture the ENTER key in order to advance cursor to next textbox? Thanks, Les "Rick Rothstein (MVP - VB)" wrote: Try using the TextBox's KeyPress event instead of its KeyDown event. Rick "WLMPilot" wrote in message ... I was given the following code for a combobox to have cursor advance to next field if the ENTER button was pressed. Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then txtQty.SetFocus End Sub However, I am finding out that this does not work for textboxes, since you have to type (keydown) in a textbox vs choosing from a list. I want the cursor to advance to the next textbox, and have the backcolor turn yellow to show current field. How does the PRIVATE Sub need to read since KEYDOWN is not appropriate? Private Sub Textbox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then textbox2.SetFocus Textbox2.Backcolor = vbYellow End Sub Thanks, Les |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You kept the same code inside the routine, didn't you? Change your use of KeyCode to KeyAscii (note the argument inside the parentheses for both the KeyCode and KeyPress events... this is what you are checking to see if its value is 13) in your If-Then test and the code should work for you.
KeyDown reads the keys on the keyboard by a location value (KeyCode) for that key; this value has nothing to do with the character the key "types". Its companion event, KeyUp, does the same thing. KeyPress, on the other hand, reads the character code (ASCII code) that the key represents. Consider it a fluke that the Enter key has the same code value for all of these events... usually, the KeyCode and KeyAscii for the same key are completely different numbers. You might want to check out this all out in the help files (look up KeyDown and KeyPress). Rick "WLMPilot" wrote in message ... Did not work. Did the same thing. What is the difference between KeyDown and KeyPress? Sounds like they both check for the same thing. Any other ideas that will capture the ENTER key in order to advance cursor to next textbox? Thanks, Les "Rick Rothstein (MVP - VB)" wrote: Try using the TextBox's KeyPress event instead of its KeyDown event. Rick "WLMPilot" wrote in message ... I was given the following code for a combobox to have cursor advance to next field if the ENTER button was pressed. Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then txtQty.SetFocus End Sub However, I am finding out that this does not work for textboxes, since you have to type (keydown) in a textbox vs choosing from a list. I want the cursor to advance to the next textbox, and have the backcolor turn yellow to show current field. How does the PRIVATE Sub need to read since KEYDOWN is not appropriate? Private Sub Textbox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then textbox2.SetFocus Textbox2.Backcolor = vbYellow End Sub Thanks, Les |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Fixed it! The problem was not with KEYDOWN, but with the If statement. The
first example I showed you worked and I was only performing one thing if ENTER pressed. However, the second code I gave needed to do TWO things if ENTER pressed and I did not change the IF statement to reflect that. Therefore, everytime I pressed down a key in a textbox, the color for the next textbox changed yellow. As I re-read my original question, I should have put that the color was changing in the next textbox prematurely. Sorry. Thanks anyway, Les "Rick Rothstein (MVP - VB)" wrote: Try using the TextBox's KeyPress event instead of its KeyDown event. Rick "WLMPilot" wrote in message ... I was given the following code for a combobox to have cursor advance to next field if the ENTER button was pressed. Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then txtQty.SetFocus End Sub However, I am finding out that this does not work for textboxes, since you have to type (keydown) in a textbox vs choosing from a list. I want the cursor to advance to the next textbox, and have the backcolor turn yellow to show current field. How does the PRIVATE Sub need to read since KEYDOWN is not appropriate? Private Sub Textbox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then textbox2.SetFocus Textbox2.Backcolor = vbYellow End Sub Thanks, Les |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
keydown, arrow keys problem | Excel Programming | |||
Keydown and SelStart problem | Excel Programming | |||
keydown event | Excel Programming | |||
keydown event | Excel Programming | |||
keydown event | Excel Programming |