AfterUpdate Code

J

Joe

This is message is being posted for code evaluation/correction to a problem
for which a partial solution was provided by "Klatuu". Any insight from the
"MVPs" or anyone with a solution will be greatly appreciated. I am not a code
expert so a simple suggestion/solution specific to the solution will be most
useful.

The code below changes the background color of a drop down menu choices when
placed in the After Update code section. However, the last two colors, “Blueâ€
and Orange†have a black text that shows trough the color background. Why?


Me.Combo56.BackColor = IIf(IsNull(Me.Combo56.Value) = True, 15066597,
Switch(Me.Combo56.Value = "Green", 65280, Me.Combo56.Value = "Yellow", 65535,
Me.Combo56.Value = "Red", 255, Me.Combo56.Value = "Blue", 16737843,
Me.Combo56.Value = "Orange", 5220351))
 
D

Douglas J. Steele

I'm not sure I understand what you mean by "have a black text that shows
trough the color background". The code changes the back colour only, not the
text colour.
 
J

Joe

Sorry, Doug. I am trying to get the background color to change when selected
from the drop down without the name of the color showing like the result
achieved when conditional formatting is used. This purely cosmetic and I can
live with what I am getting now if my question/query does not make sense.
 
B

BruceM

I can't say I follow what you're doing, but maybe you could set the
forecolor to match the backcolor. However, I expect you would still see the
text when you click into the combo box.

You mention the After Update event. Is that for the combo box? If so, are
you selecting a color name from the combo box for the express purpose of
changing the combo box backcolor? If so, what is supposed to happen when
you go to another record?

BTW, Value is the default property for a combo box, text box, etc., so you
don't need to specify it. Also, If IsNull is enough of a test; you don't
need to check whether it's true:

Me.Combo56.BackColor = IIf(IsNull(Me.Combo56), 15066597,
Switch(Me.Combo56 = "Green", 65280,
Me.Combo56 = "Yellow", 65535,
Me.Combo56 = "Red", 255,
Me.Combo56 = "Blue", 16737843,
Me.Combo56 = "Orange", 5220351))

There's no harm to doing it the way you did, but it is easier to read and
evaluate if it is pared down to the essentials.
 
J

Joe

Thanks BrueM,

Without following what I am doing, you've managed to hit the nail on the
head. I have tried setting the forecolor to match the backcolor - exactly
what I want. However, in this instance, the text is not visible when you
click into the comb box making it difficult to know what color to select. I
want the text to be visible when I click into the combo box but invisible
when a color is selected.

Any ideas?

Thanks.
 
B

BruceM

You could use the combo box Enter event (or maybe the Click event) to set
the forecolor. For instance:
Me.Combo56.ForeColor = vbWhite

If the forecolor depends on the current backcolor you would need to test for
that first, and choose a forecolor accordingly.

In the After Update event for Combo56, after the code to select the
backcolor:

Me.Combo56.ForeColor = Me.Combo56.BackColor
 
J

Joe

No, no, no Linq,

I do want the backcolor to change and see what is selected. What I don't
want is to have the text of selecte color visible in the background color in
black or any other color but the color of the background rendering it (textO
invisible.

Sorry if it came across as if I did not want to see what was being selected.
I currently see what is selected. What I do not want is to see the text after
the selection.

Does this change your suggestion?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top