Color the selected textbox
Solved
DEVPLUS
Posted messages
30
Status
Member
-
f894009 Posted messages 17417 Registration date Status Member Last intervention -
f894009 Posted messages 17417 Registration date Status Member Last intervention -
Bonjour,
I have 43 text boxes, and I would like to replace the formulas below
for example:
Private Sub TextBox2_Enter()
TextBox2.BackColor = vbYellow
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.BackColor = vbWhite
End Sub
Private Sub TextBox3_Enter()
TextBox3.BackColor = vbYellow
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox3.BackColor = vbWhite
End Sub
with a simpler formula that encompasses everything, like for example objcontrol, which I can't manage to solve
Private Sub TextBox_Enter()
for each objcontrol in U1.controls
if type of objcontrol is ms form.textbox then
objcontrol.backcolor=vbYellow
End Sub
it doesn't work
Configuration: Windows / Chrome 69.0.3497.100
I have 43 text boxes, and I would like to replace the formulas below
for example:
Private Sub TextBox2_Enter()
TextBox2.BackColor = vbYellow
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.BackColor = vbWhite
End Sub
Private Sub TextBox3_Enter()
TextBox3.BackColor = vbYellow
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox3.BackColor = vbWhite
End Sub
with a simpler formula that encompasses everything, like for example objcontrol, which I can't manage to solve
Private Sub TextBox_Enter()
for each objcontrol in U1.controls
if type of objcontrol is ms form.textbox then
objcontrol.backcolor=vbYellow
End Sub
it doesn't work
Configuration: Windows / Chrome 69.0.3497.100
3 answers
Hello,
But all the textboxes will be yellow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Private Sub TextBox2_Enter() TextBox_Enter End Sub Private Sub TextBox_Enter() Dim objcontrol As Object For Each objcontrol In U1.Controls If TypeOf objcontrol Is msform.TextBox Then objcontrol.BackColor = vbYellow End If Next End Sub
But all the textboxes will be yellow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
DEVPLUS
Posted messages
30
Status
Member
It is not what I want, the selected textbox must be colored and once deselected it becomes white again.
Hello,
Is it you who wrote this:
objcontrol that I can't solve
it doesn't work
and I wrote this with the code I wrote:
But all the textboxes will be yellow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
It's quite simple to solve, are you doing it or do we help you??
Is it you who wrote this:
objcontrol that I can't solve
Private Sub TextBox_Enter() for each objcontrol in U1.controls if type of objcontrol is ms form.textbox then objcontrol.backcolor=vbYellow End Sub
it doesn't work
and I wrote this with the code I wrote:
But all the textboxes will be yellow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
It's quite simple to solve, are you doing it or do we help you??
Re,
You will do for the rest of the TextBoxes
You will do for the rest of the TextBoxes
Private Sub TextBox2_Enter() Call TextBox_Enter(2, "En") End Sub Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean) Call TextBox_Enter(2, "Ex") End Sub Private Sub TextBox3_Enter() Call TextBox_Enter(3, "En") End Sub Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean) Call TextBox_Enter(3, "Ex") End Sub Private Sub TextBox4_Enter() Call TextBox_Enter(4, "En") End Sub Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean) Call TextBox_Enter(4, "Ex") End Sub Private Sub TextBox_Enter(NTB, Ev) Dim objcontrol As Object If Ev = "En" Then coul = vbYellow ElseIf Ev = "Ex" Then coul = vbWhite End If Me.Controls("Textbox" & NTB).BackColor = vbYellow For Each objcontrol In Me.Controls If TypeOf objcontrol Is MSForms.TextBox And objcontrol.Name <> "TextBox" & NTB Then objcontrol.BackColor = vbWhite End If Next End Sub