PDA

View Full Version : Solved: UserForm KeyDown Button Forces cursor to jump to next textbox



ChloeRadshaw
06-08-2009, 12:13 PM
I have a bunch of textboxes on a multipage - Each of these have wordwrap set to true, multiline set to true and enterkeybehaviour set to true.


If I press the down key in one of these fields I notice that the cursor moves to THE NEXT input box which I definitely do not want.

Does anyone know how to prevent this??

Kenneth Hobs
06-08-2009, 02:22 PM
That would be something other than what one would typically expect.

Here is one way.
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 40 Then SendKeys "{UP}"
End Sub

mikerickson
06-08-2009, 05:49 PM
This avoids SendKeys. The UF completely ignores the {up} key when TextBox1 has the focus.
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 40 Then KeyCode = 0
End Sub

ChloeRadshaw
06-09-2009, 01:18 AM
This avoids SendKeys. The UF completely ignores the {up} key when TextBox1 has the focus.
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 40 Then KeyCode = 0
End Sub

Thanks - But I dont see why this is necessary - Why is the textbox doing this in the first place?

Is this a property I have set???

Kenneth Hobs
06-09-2009, 05:26 AM
It is working as designed. When you do that in an Excel cell in goes to the next cell down. That sort of navigation goes by control type as well.

ChloeRadshaw
06-09-2009, 03:35 PM
Are you sure about this?

This only happens for multi line text boxes from the looks of things. Is there anything on MSDN which confirms this??

ChloeRadshaw
06-11-2009, 04:05 PM
I would like to close this but I have not had any confirmation that this is working as designed

Does anyone have a link to a reliable source where this is discussed please.

Thank you