conditional formatting 2 text boxes

thierry14

New member
Local time
Yesterday, 22:13
Joined
Jun 2, 2006
Messages
7
hi
is it possible to conditionally format a text box based on the value of another text box on the same form? If so hows it done?

thanks v much
 
Depends, but yes it can be done in single-forms view. Some issues exist for continuous forms view and the search function might lead you where you want to go.

You need VBA code to do this. Ideally, you write a subroutine in the class module of the form. It does the formatting. Then for each text box that controls the format of another box, call the subroutine on the AfterUpdate event for that text box. One last call from the FormCurrent event takes care of the formatting actions.

Now, as to the formatting decisions. In this subroutine you can control just about anything that is a property of the target text box. Foreground color, background color, font characteristics, etc. If it is a value-based decision, you write an IF statement in VBA for each decision.

IF CLng([TextBox1]) = 0 then TextBox2.Forecolor = VBRed
IF CLng([TextBox2]) > 6 then TextBox3.Backcolor = VBGreen
etc. etc.

In essence, write EACH POSSIBLE condition in the subroutine, which you will execute EVERY TIME something changes that could affect the formatting. Which is to say, after a record change (FormCurrent) or after a change for any of the controlling boxes (AfterUpdate).
 

Users who are viewing this thread

Back
Top Bottom