How do I change font color based on a database field?

How do I change font color based on a database field?

1. Open the designer and add the following function to the Functions tab of the Properties window:
def depcolor(dep):
  s = str(dep)
  if s == 'Name of Department 1':
    return 'Red'
  elif s == 'Name of Department 2':
    return 'Green'
  else:
    return 'Black'
2. Add a variable called dep to the Variables tab of the Properties window.

3. Select the DEPARTMENT column in the Data tab on the left-hand side of the main window, drag it to the Variables tab in the Properties window and drop it in the value text box of dep (in version 7.0 drag-and-drop is not available and you have to map the variable in the mappings window after finishing the steps below).

4. Select the text object whose color you want to control and go to the Expressions tab of the Properties window.

5. Type in the expression box for the Foreground property the following expression:
depcolor(dep)