Think I may have screwed myself...

R

rci

mmm... now I've done it.

I made a keyboard, on-screen, for a touchscreen in a userform. Works great!
It adds characters one at a time into a specific textbox.

Oops....

Now I need to add a few more text boxes... and I want it to go into the text
box with the current focus... problem is, which text box has the current
focus? Because as soon as I press the keyboard keys (Label objects) it is
*they* that have the current focus!

Think I'm in a spot of trouble here :)

Any ideas very much appreciated....

SMS
 
N

NickHK

Labels cannot take focus. With this, focus always remains on the text box.

Private Sub Label1_Click()
TextBox1.Text = TextBox1.Text & "A"
End Sub

Do you mean "ActiveControl" ?

NickHK
 
R

rci

Thx Nick,

Well, that is good news... so, how do I find what text box (if any) has the
current focus, and then, having that identified in a variable, how do I use
that variable to enter text into the text box?

Seems it would have to go like this: (psydocode)

CurrentTextBox = Me.HasFocus

CurrentTextox.value = CurrentTextBox.value & NewKeyPressed


Looks simple enough... how come I doubt it is :)

Thx!





: Labels cannot take focus. With this, focus always remains on the text box.

: Private Sub Label1_Click()
: TextBox1.Text = TextBox1.Text & "A"
: End Sub

: Do you mean "ActiveControl" ?

: NickHK

: : > mmm... now I've done it.
: >
: > I made a keyboard, on-screen, for a touchscreen in a userform. Works
: great!
: > It adds characters one at a time into a specific textbox.
: >
: > Oops....
: >
: > Now I need to add a few more text boxes... and I want it to go into the
: text
: > box with the current focus... problem is, which text box has the current
: > focus? Because as soon as I press the keyboard keys (Label objects) it is
: > *they* that have the current focus!
: >
: > Think I'm in a spot of trouble here :)
: >
: > Any ideas very much appreciated....
: >
: > SMS
 
N

NickHK

The form has an Activecontrol property.

Private Sub Label1_Click()
ActiveControl.Text = ActiveControl.Text & " A"
End Sub

Depending on your form/needs, you should check what the ActiveControl is.
If TypeOf ActiveControl Is MSForms.TextBox Then ..


NickHK
 

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