In a Control: Type some text, then hit a hotkey to append more text (?)

  • Thread starter Thread starter croy
  • Start date Start date
C

croy

In a text control on a form, I'd like to be able to type
some text, and then be able to hit a hotkey (before leaving
or saving the field), and have the hotkey append some
"canned" text in front of the text already typed. The
canned text is something that would be occasionally added,
and when it is added, would always be the same.

I've tried using OldValue, but it doesn't seem like the text
entered manually has become OldValue until the focus leaves
the control--true?

I could tell the users to hit the hotkey first, then add
their additional text, but that's not quite as forgiving for
the user.

Any ideas appreciated.
 
croy said:
In a text control on a form, I'd like to be able to type
some text, and then be able to hit a hotkey (before leaving
or saving the field), and have the hotkey append some
"canned" text in front of the text already typed. The
canned text is something that would be occasionally added,
and when it is added, would always be the same.

I've tried using OldValue, but it doesn't seem like the text
entered manually has become OldValue until the focus leaves
the control--true?

I could tell the users to hit the hotkey first, then add
their additional text, but that's not quite as forgiving for
the user.

Any ideas appreciated.

You might try something like this in the KeyDown event (of TextBox1 for
example)to intercept a hotkey (Ctl-h, in this case) and insert the text.

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

If KeyCode = Asc("H") And (Shift And acCtrlMask) > 0 Then
KeyCode = 0
txtTextBox1.Text = "Prefix-" & txtTextBox1.Text
End If

End Sub
 
You might try something like this in the KeyDown event (of TextBox1 for
example)to intercept a hotkey (Ctl-h, in this case) and insert the text.

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

If KeyCode = Asc("H") And (Shift And acCtrlMask) > 0 Then
KeyCode = 0
txtTextBox1.Text = "Prefix-" & txtTextBox1.Text
End If

End Sub

Thanks--that looks interesting. I *think* I understand
it...
 
You might try something like this in the KeyDown event (of TextBox1 for
example)to intercept a hotkey (Ctl-h, in this case) and insert the text.

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

If KeyCode = Asc("H") And (Shift And acCtrlMask) > 0 Then
KeyCode = 0
txtTextBox1.Text = "Prefix-" & txtTextBox1.Text
End If

End Sub

Like a charm! Thanks again.
 
Back
Top