Change colour of rectangle based on a field

  • Thread starter Loggical via AccessMonster.com
  • Start date
L

Loggical via AccessMonster.com

I have a form [frmEmployees] with various fields on it. I want to change the
colour of a rectangle on the same form depending on the value of a field
[Departments] chosen in the same form. The value of the field [Departments]
comes from another table [tblDepartments] and can have multiple values as
below; but only one value at any one time.

Accounts
Finance
Security
Human Resources
Housekeeping

I would like each one of the above values to have a different associated
colour.

Also what sort of Data Type should I use for this particular field
[DepartmentColour] in the table [tblDepartments]

Thanks in advance.
 
N

NG

Hi,

you can make a field tbldepartments.DepartmentColour type long and assign
the long values of the color constants you want to use in that field.
vbRed = 255
vbGreen = 65280
vbBlue = 16711680
vbYellow = 65535
(other colors you can check in the object browser or VB help)

In the oncurrent event of your form you can set the color according to the
department. Assuming the department is shown in a combo box with column 1
(hidden) the department ID , column 2 the department name, column 3 (also
hidden) the color, then you could write in the oncurrent event something like:

Me.shpRectangle.BorderColor = me.cboDepartment.Column(1)

Kind regards
Noëlla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top