GaelicFatboy
Registered User.
- Local time
- Today, 23:04
- Joined
- Apr 17, 2007
- Messages
- 100
I'm having a spot of bother getting my head round trapping which key has been pressed when using the KeyDown event.
I'm looking for when the left arrow key is pressed so I can move the cursor to the end of the text in an text box. I've looked up the KeyCodes list in the help screen under KeyCode constants for VB applications and got the constant vbKeyLeft as the one I need to use. However using the following code...
If KeyCode = vbKeyleft Then Me.Text_SubAssyNumber.SelStart = Len(Me.Text_SubAssyNumber)
...the code just doesn't trap the left arrow key and won't move the cursor. If I use the following code...
If vbKeyleft Then Me.Text_SubAssyNumber.SelStart = Len(Me.Text_SubAssyNumber)
...the code traps every key press and moves the cursor regardless of which key was actually pressed.
However if I use the following code the arrow key is trapped correctly and the cursor is moved to the end of the text.
If KeyCode = 39 Then Me.Text_SubAssyNumber.SelStart = Len(Me.Text_SubAssyNumber)
I know I've been able to get the code working, but why does using the vbKeyLeft constant not work? Is the KeyCode list I'm looking at the wrong one.
Cheers muckers
D
I'm looking for when the left arrow key is pressed so I can move the cursor to the end of the text in an text box. I've looked up the KeyCodes list in the help screen under KeyCode constants for VB applications and got the constant vbKeyLeft as the one I need to use. However using the following code...
If KeyCode = vbKeyleft Then Me.Text_SubAssyNumber.SelStart = Len(Me.Text_SubAssyNumber)
...the code just doesn't trap the left arrow key and won't move the cursor. If I use the following code...
If vbKeyleft Then Me.Text_SubAssyNumber.SelStart = Len(Me.Text_SubAssyNumber)
...the code traps every key press and moves the cursor regardless of which key was actually pressed.
However if I use the following code the arrow key is trapped correctly and the cursor is moved to the end of the text.
If KeyCode = 39 Then Me.Text_SubAssyNumber.SelStart = Len(Me.Text_SubAssyNumber)
I know I've been able to get the code working, but why does using the vbKeyLeft constant not work? Is the KeyCode list I'm looking at the wrong one.
Cheers muckers
D