Change the background color of a text box (1 Viewer)

MikiA

New member
Local time
Today, 19:03
Joined
Sep 2, 2020
Messages
17
Hello,

I have a form and a lot of text boxes on it.
I want to change the color of the text box when the value is entered.
So, i know how to do that using conditional formating.
Also, i know how to that using after update event.....
My question is: Is it posible create a loop and check all text box on the form. If no value, back color = white, if value is there, back color = red, for example.
Something like:
Code:
Dim ctl As Control

For Each ctl In Forms!Form1.Controls
If ctl.ControlType = acTextBox .....

And where i need put that code ?
On the form current property ?

Any idea ?
 

June7

AWF VIP
Local time
Today, 10:03
Joined
Mar 9, 2014
Messages
5,423
It is but should use Conditional Formatting instead of VBA.

Yes, form Current sounds reasonable. Also, each textbox AfterUpdate or LostFocus event.
 

MikiA

New member
Local time
Today, 19:03
Joined
Sep 2, 2020
Messages
17
I have always viewed conditional formatting as a temporary solution
 

June7

AWF VIP
Local time
Today, 10:03
Joined
Mar 9, 2014
Messages
5,423
Conditional Formatting is far from a temporary solution. With VBA, all records on form will show the same settings so is not practical for continuous or datasheet. On a report, VBA would have to be in Format event which executes only for PrintPreview or direct to printer, not ReportView.
 

MikiA

New member
Local time
Today, 19:03
Joined
Sep 2, 2020
Messages
17
I understand. I will try with Conditional Formatting. Honestly, will be much for work, but result will be better i belive. Thanks for you time :)
 

Users who are viewing this thread

Top Bottom