ForeColor change on DoubleClick in Combobox (1 Viewer)

stevekos07

Registered User.
Local time
Today, 14:46
Joined
Jul 26, 2015
Messages
174
Hello. I have been having trouble accomplishing what I thought would be a fairly simple task. I have a form with a combobox, which I want to be able to change the forecolor of on double-click. So if it is black, doubleclick would turn the font red and vice versa. This is the code I have for it so far but it doesn't seem to be working. Any assistance would be greatly appreciated.

Private Sub Combo0_DblClick(Cancel As Integer)
Select Case ForeColor
Case "#ED1C24"
Me.Combo0.ForeColor = "#000000"
Case "#000000"
Me.Combo0.ForeColor = "#ED1C24"
End Select
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:46
Joined
Oct 29, 2018
Messages
21,536
Hi. Maybe you meant to say?
Code:
Select Case Me.Combo0.ForeColor
 

stevekos07

Registered User.
Local time
Today, 14:46
Joined
Jul 26, 2015
Messages
174
I tried the RGB designations instead of Hexadecimal, plus I added the Me.Combo0 as you indicated and that fixed it. Thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:46
Joined
Oct 29, 2018
Messages
21,536
I tried the RGB designations instead of Hexadecimal, plus I added the Me.Combo0 as you indicated and that fixed it. Thanks.
Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:46
Joined
Feb 19, 2002
Messages
43,477
I hate to ask the question, but are you expecting the background color to "stick"?
 

stevekos07

Registered User.
Local time
Today, 14:46
Joined
Jul 26, 2015
Messages
174
I hate to ask the question, but are you expecting the background color to "stick"?
Thanks for the comment. That's not necessary, but I might look at that later. There are quite a few fields that this is being applied to so the programming for that might be a bit too much for now.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:46
Joined
May 21, 2018
Messages
8,605
There are quite a few fields that this is being applied to so the programming for that might be a bit too much for now.
You should only have to write a single function and not multiple event procedures to apply this to more than one control. In other words one control or a hundred controls should be the same amount of code needed.
 

stevekos07

Registered User.
Local time
Today, 14:46
Joined
Jul 26, 2015
Messages
174
Ok. So if I wanted the colour to "stick" on saving and re-opening, how should I write the code?
 

Micron

AWF VIP
Local time
Today, 17:46
Joined
Oct 20, 2018
Messages
3,478
AFAIK, you would have to save the property value somewhere if this is based on an arbitrary double click because unless you set it in design view, it won't stick. So on form open, you'd have to get whatever value you've stored to affect the forecolor. That could be a table field or you could store it in the control Tag property. If this is really based on data, then conditional formatting might work, but you didn't say what kind of form it is.
 

sxschech

Registered User.
Local time
Today, 14:46
Joined
Mar 2, 2010
Messages
799
Regarding the colours, if you are using the standard ones in vba, they could be enters as vbRed for Red and vbNormal for Black

Code:
Me.Combo0.ForeColor = vbRed
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:46
Joined
Feb 19, 2002
Messages
43,477
Making the colors "stick" would require modifying your table to contain a color value for every field you want to colorize. Then in the current event of each record, you would loop through the table fields and apply the color. My advice, don't go there.
 

Micron

AWF VIP
Local time
Today, 17:46
Joined
Oct 20, 2018
Messages
3,478
There is always the tag property, as I mentioned. Not that I would do that either.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:46
Joined
Feb 28, 2001
Messages
27,317
When faced with a similar (but not identical) problem, I identified a "form state" that would provide guidelines for ALL controls. In my statuses, a form could be "Normal" (not dirty and not new data), "Virgin" (new data and dirty, based on new record), "Dirty" (not new data but something has changed), "Locked" (user is not allowed to diddle with the form), and "Incomplete" (at least one required field not filled yet). That form status allowed me to decide the color schemes for each control that had a .Value (explicit or implied). Then I could use a "For Each ctl In Me.Controls" construct and reset colors for everything that COULD have a color change under some circumstance.

The colors "stuck" because they got reasserted during the Form_Current routine based on the state of the form at that moment. As it happens, the "Current" event fired for my form's "Normal" and "Locked" and "Virgin" states. Normal and Locked depended on my user security setup. "Virgin" also went through Current because you got there by doing a DoCmd to GoTo a new record - and when it did, the form was Virgin by my definition.
 

zeroaccess

Active member
Local time
Today, 16:46
Joined
Jan 30, 2020
Messages
671
+1. I also have a SetFormState that runs on load, on status change, and a couple of other events. It mostly sets various controls' enabled property but can be used for anything.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:46
Joined
May 21, 2018
Messages
8,605
See if this is of interest. Shows how to pick different settings and same them so you can change the control format. The font picker and color picker may be of interest. I doubt I would ever do this, but some people may like this. Would allow you to configure the display for different conditions. Probably can do some better using themes.
 

Attachments

  • CustomSettingsv2.zip
    81.1 KB · Views: 83
Last edited:

Users who are viewing this thread

Top Bottom