Conditional Format:

  • Thread starter Thread starter 123
  • Start date Start date
1

123

Thank you for your help and answer:

Employee name Department

A 1

B 1

C 2

T 3

R 8

I want if department name is same for 2 or 3 fields or any number give
department and employee name red color

Another very hard question:

If the previous question is answered correctly:

Can change the color for each group of number…

Department 1 red

Department 2 any color
 
What you are asking for is to use a different color for the first employee
and the first department in each "group".

The tricky part of that request is that if the form is reordered or
filtered, the "previous" value may not be what you expect. The only safe
solution, therefore, is to check the previous value in the form's
RecordsetClone, since that gives the correct answer regardless of how the
form is sorted or filtered.

The function below returns from a specific field in the previous row of the
form. Add a text box to your form, with ControlSource set to:
=GetPreviousValue([Form], "MyField")
Leave the Form bit exactly as it is.
Replace "MyField" with the name of your field.

You can then use conditional formatting, referring to the name of this text
box in the expression.

Function GetPreviousValue(frm As Form, strField As String) As Variant
On Error GoTo Err_Handler
'Purpose: Return the value from the previous row of the form.
Dim rs As DAO.Recordset

Set rs = frm.RecordsetClone
rs.Bookmark = frm.Bookmark
rs.MovePrevious
GetPreviousValue = rs(strField)

Set rs = Nothing
Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 3021& Then 'No current record
Debug.Print Err.Number, Err.Description
End If
GetPreviousValue = Null
Resume Exit_Handler
End Function
 
Back
Top