Since there are more than 1 employee that need to be selected (with a different color background) does each one need his/her own If/Then/Else Statement,
I am bewildered that two other highly experienced developers have posted code that includes names. Code should never have data embedded into it. Data is meant to be in tables. When it needs to be referred to in code then it should be queried.
What would the users be expected to do if another person needed the formatting? Edit the code?
Galaxiom, Please do not take this any other way. I have to admit I overlooked your post, Sorry. I agree with your comments. Hard coding values is never the right way to go.
depawl - As Galaxiom suggested you need to create a more robust structure. Create a table that will hold this information. Or just create a new column in the existing (if there actually one existing) Employee table call it formatSpecifier maybe set it to Yes/No type. For Doe, John and Smith Susie set the value of the column to be True the rest be False..
Then use this column in the Query you are using to generate the report. Finall change the code, just replace the following..
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.EmployeeName = "Doe, John R-12345" Or Me.EmployeeName = "Smith, Susie L-54321" Then
Me.Employee_Name.BackColor = &HFCE6D4
Else
Me.Employee_Name.BackColor = &HFFFFFF
End If
End Sub
With this..
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.formatSpecifier Then
Me.Employee_Name.BackColor = &HFCE6D4
Else
Me.Employee_Name.BackColor = &HFFFFFF
End If
End Sub
If yes/no or anything up to four variations was required then conventional conditional formatting could be used to apply it.
There are many variations on what can be stored. A code to represent any arbitrary number of variations. Even the colours to be used in the format could be specified in the table.