how to refer checkbox in a tabcontrol? (1 Viewer)

anto.danny

Registered User.
Local time
Today, 03:20
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.
 

JHB

Have been here a while
Local time
Today, 12:20
Joined
Jun 17, 2012
Messages
7,732
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
 

anto.danny

Registered User.
Local time
Today, 03:20
Joined
Nov 8, 2015
Messages
35
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
 

anto.danny

Registered User.
Local time
Today, 03:20
Joined
Nov 8, 2015
Messages
35
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:
 

JHB

Have been here a while
Local time
Today, 12:20
Joined
Jun 17, 2012
Messages
7,732
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:20
Joined
May 7, 2009
Messages
19,230
or simply:

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

Users who are viewing this thread

Top Bottom