Preventing selection of text in text box

K

Kitty

I have users who are a bit ham-handed when using their
laptops. We have a text box where they enter sometimes
voluminous comments about the customer they're reviewing.

The Problem - Holding down shift on left side of keyboard,
and missing the key they want on the right, hitting and
arrow key instead. That highlights text in the box. They
don't realize right away, and overtype what was
highlighted.

I'm trying to capture the Shift + arrow keys in the
KeyDown event of the text box. I'm using a select case
statement. For example...

Select Case KeyCode
Case vbKeyPageDown
KeyCode=0 (this prevents PageDown)
Case (vbKeyShift and vbKeyLeft) What is the syntax
here?
KeyCode=0 (here I'm trying to prevent this from
happening)
Case Else
'do nothing
End Select

Thanks for any suggestions.

Kitty
 
G

Graham Mandeno

Hi Kitty

The state of the shift key cannot be ascertained from the KeyCode argument.
It comes from the second argument (Shift) which encodes the state of the
shift, alt and ctrl keys.

To test for the shift key, use:
If (Shift And acShiftMask) <> 0 Then
 
K

Kitty

Graham, how would I combine that with checking for the
arrow keys? I don't want to disable the shift key or the
arrow keys individually, and do if they're both pressed.

Kitty

-----Original Message-----
Hi Kitty

The state of the shift key cannot be ascertained from the KeyCode argument.
It comes from the second argument (Shift) which encodes the state of the
shift, alt and ctrl keys.

To test for the shift key, use:
If (Shift And acShiftMask) <> 0 Then

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I have users who are a bit ham-handed when using their
laptops. We have a text box where they enter sometimes
voluminous comments about the customer they're reviewing.

The Problem - Holding down shift on left side of keyboard,
and missing the key they want on the right, hitting and
arrow key instead. That highlights text in the box. They
don't realize right away, and overtype what was
highlighted.

I'm trying to capture the Shift + arrow keys in the
KeyDown event of the text box. I'm using a select case
statement. For example...

Select Case KeyCode
Case vbKeyPageDown
KeyCode=0 (this prevents PageDown)
Case (vbKeyShift and vbKeyLeft) What is the syntax
here?
KeyCode=0 (here I'm trying to prevent this from
happening)
Case Else
'do nothing
End Select

Thanks for any suggestions.

Kitty


.
 
G

Graham Mandeno

Hi Kitty

Having established that the shift key is pressed, you can then check KeyCode
for arrows:

If (Shift And acShiftMask) <> 0 Then
If KeyCode = vbKeyLeft or KeyCode = vbKeyRight then KeyCode = 0
End If

Or, if you're checking for other keys as well (like PageUp/Down) then check
KeyCode in a Case statement and *then* check Shift only if you have an
arrow:

Select Case KeyCode
Case vbKeyPageUp, vbKeyPageDown
KeyCode=0
Case vbKeyLeft, vbKeyRight
If (Shift And acShiftMask) <> 0 Then KeyCode=0
End Select

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Kitty said:
Graham, how would I combine that with checking for the
arrow keys? I don't want to disable the shift key or the
arrow keys individually, and do if they're both pressed.

Kitty

-----Original Message-----
Hi Kitty

The state of the shift key cannot be ascertained from the KeyCode argument.
It comes from the second argument (Shift) which encodes the state of the
shift, alt and ctrl keys.

To test for the shift key, use:
If (Shift And acShiftMask) <> 0 Then

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I have users who are a bit ham-handed when using their
laptops. We have a text box where they enter sometimes
voluminous comments about the customer they're reviewing.

The Problem - Holding down shift on left side of keyboard,
and missing the key they want on the right, hitting and
arrow key instead. That highlights text in the box. They
don't realize right away, and overtype what was
highlighted.

I'm trying to capture the Shift + arrow keys in the
KeyDown event of the text box. I'm using a select case
statement. For example...

Select Case KeyCode
Case vbKeyPageDown
KeyCode=0 (this prevents PageDown)
Case (vbKeyShift and vbKeyLeft) What is the syntax
here?
KeyCode=0 (here I'm trying to prevent this from
happening)
Case Else
'do nothing
End Select

Thanks for any suggestions.

Kitty


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top