Background color box when row clicked on

jonnn21

New Member
Joined
Feb 9, 2012
Messages
23
I apologize for the lame heading but I don't know how to explain it.

I have a table with a name, Red, Green, Blue fields

The Red, Green, Blue fields are the three numbers i'm using to make up the color I want (Blue= 173,192,217)ect...
I have a continuous form that has a single text box. The control source for this textbox is the NAME from that table

The continuous form works great.
All I want to do, is click on a Name and change the background of that SINGLE record to the Red, Green, Blue fields to makes up the single color

Current Code is:
Me.txt_Name.BackColor = RGB(Me.Txt_red, Me.txt_green, Me.Txt_blue)

I have txt_red, txt_green, txt_blue as test boxes (control source to the table of course) as well and those are what is being referred to in the VBA code.
But this changes the color of ALL the records, not just the single record im on.

Suggestions?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Access question.

The only way I know how do this is using conditional formatting.

VBA Code:
Private Sub Form_Current()
    With txt_Name.FormatConditions
        .Delete
        .Add acFieldHasFocus
        .Item(0).BackColor = RGB(Red, Blue, Green)
    End With
End Sub
 
Upvote 0
You should be able to do this with the conditional format dialog as well (ribbon) Format> Conditional Formatting. I believe the limit is 3 formats regardless of which method you use.
On a continuous form, there is only 1 "textbox1" - what you see are multiple instances of it, so anything you do to it outside of cf will be applied to all instances of it. As for data, if not bound and you make one contain "cat" they all will.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top