Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Formatting for Check Box 2

Status
Not open for further replies.

cstuart79

Technical User
Nov 2, 2009
171
US
So I have the following code added to a check box on a continuous form.

Private Sub Check32_Click()
If Me.Check32.Value = True Then
Me.Sender_Comp_ID.BackColor = RGB(0, 255, 0)
Me.Port.BackColor = RGB(0, 255, 0)
Else
Me.Sender_Comp_ID.BackColor = RGB(255, 255, 255)
Me.Port.BackColor = RGB(255, 255, 255)
End If
End Sub

The code is successful in changing the color of the field upon clicking the checkbox; however, all records change colors when 1 single checkbox is clicked. Please help me revise the code to make it so each checkbox for each entry is unique! I know this needs conditional formatting.

I tried the following but was unsuccessful:

Dim objFrc As FormatCondition
Dim lngGreen As Long
lngGreen = RGB(0, 255, 0)

Me.Sender_Comp_ID.FormatConditions.Delete
Set objFrc = Me.Sender_Comp_ID.FormatConditions.Add(Check32.Value = True)

With Me.Sender_Comp_ID.FormatConditions
.Add.BackColor = RGB(0, 255, 0)
End With

End Sub

Maybe I simply add the "FormatConditions.Delete" clause?

Private Sub Check32_Click()
If Me.Check32.Value = True Then
Me.Sender_Comp_ID.BackColor = RGB(0, 255, 0)
Me.Port.BackColor = RGB(0, 255, 0)
Else
Me.Sender_Comp_ID.BackColor = RGB(255, 255, 255)
Me.Port.BackColor = RGB(255, 255, 255)
End If
End Sub

Or add the clause to this that references parent form?

Private Sub Check32_AfterUpdate()
If Me.Parent.SESSIONS.Check32.Value = True Then
Me.Sender_Comp_ID.BackColor = RGB(0, 255, 0)
Me.Port.BackColor = RGB(0, 255, 0)
 
Why not simply add the conditional formatting in design view ?
NO VBA needed !

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I suggested exactly the same in thread702-1578626. Apparently cstuart79 likes to use code where it won't work. Also "but was unsuccessful" doesn't provide any clue about your results, error message, changes, etc.

Duane
Hook'D on Access
MS Access MVP
 
How are ya cstuart79 . . .

Agree with [blue]PHV[/blue]. Its a simple matter of setting your [blue]conditional format expression[/blue] to:
[purple][Check32] = True[/purple] and selecting the background color from the [blue]conditional format[/blue] dialog ...

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
thanks Ace Man--i simply needed to add [ ] around Check32 and it worked perfectly. much appreciated--that was driving me crazy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top