lundi 26 mai 2014

VBA Getting name of last active textbox without using global variable


Vote count:

0




I've got textBox1 and textBox1 and a couple of buttons (button1 is enought in this example), I would like to use those buttons in goal to manipulate texts in textboxes. If last active was textBox1 then button1 should change only text in it (for example convert text into lowercase form), after using button1 again with no other action taken in the middle the modified text should text in textBox1, this situation repeats until user activate textBox2.


With global variable solution is as follows :



Dim textLastActive As String

Public Sub textBox1_enter()
textLastActive = "textBox1"
End Sub

Public Sub textBox2_enter()
textLastActive = "textBox2"
End Sub

Sub button1_Click()
If textLastActive = "textBox1" then
'do something with textBox1.text
Else
'do something with textBox2.text
End If
End Sub


asked 1 min ago

Qbik

611





Aucun commentaire:

Enregistrer un commentaire