Using table values to control form properties. (1 Viewer)

D

Darke

Guest
I want to use the values in a table to control the way labels appear in a form using the form_load procedure. I have a boolean value (yes/no) in a table that I want the procedure to lookup for each value in a table, and then in the corresponding label on the form, I want it to change the background color accordingly. Ie;
Table: Tablename
ID Yes/No
1 Yes
2 No
3 No
4 Yes
5 No
-----
Form Properties:
Label1.backcolor = Blue
Label2.backcolor = Red
Label3.backcolor = Red
Label4.backcolor = Blue
Label5.backcolor = Red

Any suggestions on how to get this to work in access? Or am I approaching it from the wrong direction?

-Darke
 

Axis

Registered User.
Local time
Today, 23:02
Joined
Feb 3, 2000
Messages
74
I don't know of a way to change multiple controls on a form without referring to each of them, so here is my suggestion:

[YourForm].OnCurrent

If [YourField] = Yes Then
Me!Label1.backcolor = 16711680
Me!Label2.backcolor = 16711680
Me!Label3.backcolor = 16711680
Me!Label4.backcolor = 16711680
Me!Label5.backcolor = 16711680
Else
Me!Label1.backcolor = 255
Me!Label2.backcolor = 255
Me!Label3.backcolor = 255
Me!Label4.backcolor = 255
Me!Label5.backcolor = 255
End if

Access uses several blues, so you may need to select a different reference number for the blue you want.

Also, I used OnCurrent rather than OnLoad in case your users scroll from one record to another on your form. OnCurrent will re-evaluate each time a new record is displayed.
 
D

Darke

Guest
Ok, but the form is not bound to any tables, so I need to use a table without it being bound to the form, so I need someway to reference the data in the table from a Module. You know, the way forms uses the Forms![Formname]![Etc..]
 

Axis

Registered User.
Local time
Today, 23:02
Joined
Feb 3, 2000
Messages
74
You can use DLookup to find the value of a field in a table that is not open. Look in Help for more details. Declare a variable and set it to the results of the DLookup action. Then use the same code as before, but substitute the variable name for [YourField].

[This message has been edited by Axis (edited 05-01-2000).]
 

Users who are viewing this thread

Top Bottom