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

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.
 
M

Michael J. Strickland

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
 
C

croy

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...
 
C

croy

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.
 

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