Combo Box Backcolor in Continuous Form (1 Viewer)

Thumper75

Registered User.
Local time
Yesterday, 22:48
Joined
Feb 6, 2017
Messages
37
My part monitor form is a columnar form displaying 4 fields from a table. The Status field only has 2 inputs, Open and Accomplished. The goal is to display the Status field in Yellow if the value is Open. This has been working fine, but if I change the value to Accomplish it changes to white. This code works fine, however it is changing the field background to white for all the records even if the value is Open, regardless of which record I update.

Code:
Private Sub Form_GotFocus()

If Me.txt_stat.Value = "Open" Then
    Me.txt_stat.BackColor = 65535
ElseIf Me.txt_stat.Value = "Accomplished" Then
    Me.txt_stat.BackColor = 16777215
End If

End Sub

I'm sure this is something simple that I'm missing, at least I hope its simple. Anyone have any ideas?
 

Thumper75

Registered User.
Local time
Yesterday, 22:48
Joined
Feb 6, 2017
Messages
37
Galaxiom, I thought I was using conditional formatting. Hence the reason for my confusion.
 

Thumper75

Registered User.
Local time
Yesterday, 22:48
Joined
Feb 6, 2017
Messages
37
Galaxiom, I found what I was looking for. That did the trick. Thanks for the suggestion.
 

missinglinq

AWF VIP
Local time
Yesterday, 23:48
Joined
Jun 20, 2003
Messages
6,423
...I thought I was using conditional formatting...

Just as an explanation...you were using conditional formatting...notice the Lower Case...as opposed to Conditional Formatting...off of the Ribbon.

While you see txt_stat multiple times, on a Datasheet or Continuous View Form, you're actually only seeing multiple instances of a single Control...not multiple Controls...hence the need for Conditional Formatting off of the Ribbon.

Using code, as you originally tried, works fine, in a Single View Form.

There are only two instances, to my knowledge when you can use code to Format a Datasheet or Continuous View Form...when you are Locking a Control, or Locking/Disabling a Control. This is because these actions don't effect the appearance of the Control, only its functioning...and will do this, appropriately, as you move from Record to Record, using something like this:

Code:
Private Sub Form_Current()
 If Not IsNull(Me.ControlName) Then
  Me.ControlName.Locked = True
 Else
  Me.ControlName.Locked = False
 End If
End Sub

Linq ;0)>
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:48
Joined
Jan 20, 2009
Messages
12,847
There are only two instances, to my knowledge when you can use code to Format a Datasheet or Continuous View Form...when you are Locking a Control, or Locking/Disabling a Control.

ConditionalFormatting supports conditional Enable without having to use VBA.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:48
Joined
May 21, 2018
Messages
8,439
There are only two instances, to my knowledge when you can use code to Format a Datasheet or Continuous View Form

It is not completely true. You can leverage the OnPaint event. As mentioned there is only one control but in a continous form the other visible controls are "painted".

The following sets the value of the SelectedID and then requeries causing everything to get repainted. The selected row turns yellow.

Code:
Dim SelectedID As Long

Private Sub Command34_Click()
  SelectedID = Me.Products_ProductID
  Me.Requery
End Sub

Private Sub Detail_Paint()
  If SelectedID = Me.Products_ProductID Then
    Me.ProductName.BackColor = 65535
  Else
    Me.ProductName.BackColor = 16777215
  End If
End Sub

Conditional formatting is the way to go, but this can be useful for certain things.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:48
Joined
Jan 20, 2009
Messages
12,847
It is not completely true. You can leverage the OnPaint event. As mentioned there is only one control but in a continous form the other visible controls are "painted".

The following sets the value of the SelectedID and then requeries causing everything to get repainted. The selected row turns yellow.

Only the current record reflects the conditional formatting using this technique.

BTW Requerying the form would be inefficient way to get it to repaint. Why not simply use the Me.Repaint ? Moreover a Requery would return to the first record again.

I use a similar technique to put a highlight behind the whole row on the current record.

Use the Current Event to write the record ID to a text box in the header. Then use ConditionalFormatting to set the backcolor by comparing the current record ID with the textbox in the header.

The current event fires no matter how you change records rather than depending on clicking a particular control. Having a control behind the transparent backstyle controls displaying the data means the whole row can be highlighted with a single change.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:48
Joined
May 21, 2018
Messages
8,439
Only the current record reflects the conditional formatting using this technique.
BTW Requerying the form would be inefficient way to get it to repaint. Why not simply use the Me.Repaint ? Moreover a Requery would return to the first record again.
I use a similar technique to put a highlight behind the whole row on the current record.
Use the Current Event to write the record ID to a text box in the header. Then use ConditionalFormatting to set the backcolor by comparing the current record ID with the textbox in the header.
The current event fires no matter how you change records rather than depending on clicking a particular control. Having a control behind the transparent backstyle controls displaying the data means the whole row can be highlighted with a single change.
Yes it was meant to be an example of the paint event, not a working solution or an answer to this problem. There are some things using this event that you could not accomplish with conditional formatting. In other words you can completely format any records.
 

Users who are viewing this thread

Top Bottom