Sendkeys Problem

J

John C.

I have a form with a text box. It is enabled and not
locked.

I want to sendkeys to the text box to place
(1) 'CTRL+1
(2) 'CTRL+2
(3) 'CTRL+3
...up to CTRL+9

Private Sub Text0_KeyDown(KeyCode As Integer, Shift As
Integer)

Select Case Shift
Case 2
If KeyCode >48 and KeyCode < 57 Then
SendKeys "+9" 'Shift+9 to place left paren
SendKeys KeyCode-48 'Place numeric
SendKeys "+0" 'Shift+0 to place right paren
KeyCode = 0 'Cancel anyother keystroke
End If
End Select
End Sub


I can not get the code to work...
 
J

John Vinson

I have a form with a text box. It is enabled and not
locked.

I want to sendkeys to the text box to place
(1) 'CTRL+1
(2) 'CTRL+2
(3) 'CTRL+3
...up to CTRL+9

SendKeys is buggy (it unpredicatably toggles the computer's NumLock
setting, among other things) and unnecessary. There's just about
always a better way!

In this case, I'd set the Form's KeyPreview property to True, and put
code in the textbox's On Key Press event. In that event's code you can
set the textbox's value to the desired text string.
 
T

TC

Why sendkeys? Can't you just set the Value or Text property of the textbox
to what you want?

HTH,
TC
 

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