how to refer checkbox in a tabcontrol?

anto.danny

Registered User.
Local time
Yesterday, 18:05
Joined
Nov 8, 2015
Messages
35
Greetings,

I made a tab control called TabCtl54 which has a pages named hello world and hello earth. I have a checkbox named 14 place on the page hello earth.

I placed a textbox called txtbx on the form.

Now I want a vba code that would change the backcolor of txtbx to yellow when the checkbox 14 is true.

CODE
Code:
Private Sub Form_Current()
Me.TabCtl54.Value = 1
If 14 = True Then
txtbx.BackColor = vbYellow
End If
End Sub

I get no error in runtime, except that the txtbx doesn't change color when the checkbox is checked.
 
Do only use numbers for control name - so rename the checkbox to Check14 - and use the Me. in front of the controls.
Code:
If [B][COLOR=Red]Me.Check[/COLOR][/B]14 = True Then 
[B][COLOR=Red]  Me.[/COLOR][/B]txtbx.BackColor = vbYellow 
End If
 
Do only use numbers for control name - so rename the checkbox to Check14 - and use the Me. in front of the controls.
Code:
If [B][COLOR=Red]Me.Check[/COLOR][/B]14 = True Then 
[B][COLOR=Red]  Me.[/COLOR][/B]txtbx.BackColor = vbYellow 
End If

CHEERS MATE!!!!!!!!!Finally I can have a peaceful coffee break :D
 
It worked but when I move to the next record which has the check14 unchecked but the txtbx is still yellow..tried pasting the code in before and after events..no luck..:banghead::banghead::banghead:
 
Then you need the else part of the If structure.

Code:
If Me.Check14 = True Then
  [COLOR=Red][COLOR=Black]Me.[/COLOR][/COLOR]txtbx.BackColor = vbYellow
[COLOR=Red][B]Else
  Me.txtbx.BackColor = vbBlack
[/B][/COLOR]Endif
End If
 
or simply:

Me.txtbx.BackColor = IIF(Me.check14, vbYellow, vbBlack)
 

Users who are viewing this thread

Back
Top Bottom