Solved Changing the colour of a textbox on a continuous form based on a combobox (1 Viewer)

Sam Summers

Registered User.
Local time
Today, 12:26
Joined
Sep 17, 2001
Messages
939
I have tried so many things to achieve this and no luck.

I am trying to conditionally change the backcolour of a textbox on a continuous form based on a combobox value on the same form.

I tried conditional formatting and also vba in the on load event of the form but nothing works?

Any ideas?

Many thanks in advance
 

Ranman256

Well-known member
Local time
Today, 08:26
Joined
Apr 9, 2015
Messages
4,337
Make the combo box have 2 columns,
Item to pick and the color.

In the afterupdate event:
Me.backcolor = cboBox.column(1)

Note: in vb,columns begin with zero.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:26
Joined
May 21, 2018
Messages
8,463
Above will not work. It cannot be done in a continuous form using vba. Must use CF
backcolour of a textbox on a continuous form
Expression is: [CboBoxName] = "SomeValue"
 

Sam Summers

Registered User.
Local time
Today, 12:26
Joined
Sep 17, 2001
Messages
939
Above will not work. It cannot be done in a continuous form using vba. Must use CF

Expression is: [CboBoxName] = "SomeValue"
Its not the combobox i want to change the colour of. I want to change the colour of the textbox based on what is selected in the combobox if its possible. Basically i am reducing the combobox to nothing and making the textbox display the contents of the combobox so that the user isn't tempted to try and select from the drop down list.

Hope that makes sense?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:26
Joined
May 21, 2018
Messages
8,463
I want to change the colour of the textbox based on what is selected in the combobox if its possible.
Yes that is exactly why I used "Expression Is" instead of "Field Value Is" .
cond.jpg
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:26
Joined
May 21, 2018
Messages
8,463
Is the value you are looking for really the 3rd column (0 based) and it is not the bound field? Make sure status is the name of the combo. Also no [] around Column. Only needed around the control name.
 

Sam Summers

Registered User.
Local time
Today, 12:26
Joined
Sep 17, 2001
Messages
939
Is the value you are looking for really the 3rd column (0 based) and it is not the bound field? Make sure status is the name of the combo. Also no [] around Column. Only needed around the control name.
Yes done all that and checked that i am referring to the right column and still nothing? Very strange
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:26
Joined
May 21, 2018
Messages
8,463
See demo

cond2.jpg
 

Attachments

  • Conditional.accdb
    456 KB · Views: 425

Sam Summers

Registered User.
Local time
Today, 12:26
Joined
Sep 17, 2001
Messages
939
Right i think i have found the problem. Its because i want the textbox to display the text in the combobox with this - =[Status].[Column](2)
'Status' being the name of the combobox.

It must be conflicting with the conditional formatting expression?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:26
Joined
May 21, 2018
Messages
8,463
Even if Status is a reserved word (which it is not), it would not matter since it is inside [].
You do not need the [] around column, but I tested it with them and it works.
Can you post your db or a sample?
 

Sam Summers

Registered User.
Local time
Today, 12:26
Joined
Sep 17, 2001
Messages
939
Even if Status is a reserved word (which it is not), it would not matter since it is inside [].
You do not need the [] around column, but I tested it with them and it works.
Can you post your db or a sample?
Here it is and thank you
 

Attachments

  • Asset Maintenance System - Copy.zip
    474.5 KB · Views: 346

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:26
Joined
May 21, 2018
Messages
8,463
You need to get rid of the table lookups. These are BAD! You are also creating so much extra work in what you are attempting. See the simple query and simple formatting.

You make combo lookups on forms not in tables. Yes I know that MS thought they were doing people a favor, but they just made it easy to hang yourself.
 

Attachments

  • Asset Maintenance System - MajP.zip
    466.4 KB · Views: 229

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:26
Joined
May 21, 2018
Messages
8,463
FYI. One more thing. Conditional formatting does not work well with transparent controls. In order to change the back color need to set to Normal. I made it look transparent, by giving the background color same as the form color.
 

Sam Summers

Registered User.
Local time
Today, 12:26
Joined
Sep 17, 2001
Messages
939
FYI. One more thing. Conditional formatting does not work well with transparent controls. In order to change the back color need to set to Normal. I made it look transparent, by giving the background color same as the form color.
Thank you. I note all your points and will have a go at putting it into action. I am slowly learning
 

Users who are viewing this thread

Top Bottom