Clearing a Form Controls background color when there is data in the cell

On a form which has all of its  text controls  background color set to 14155775, I would like code that would be called for each form controls  "on exit event", which would change the backcolor to normal if the field has had some data entered into it else leave it as 14155775.

Many thanks.

PeterWhitts
LVL 1
PeterWhittsAsked:
Who is Participating?
 
Leigh PurvisDatabase DeveloperCommented:
Doh - damn air code...

Set ctl  = Me.ActiveControl
 ^---------- vital
0
 
Leigh PurvisDatabase DeveloperCommented:
You mean...

sub UpdateColour()

dim ctl as Control
ctl  = Me.ActiveControl

With ctl  
    If not isnull(.Value) Then
       .backcolor = -2147483643
    End If
End With

Set ctl = nothing
End Sub

Calling UpdateColour as you exit each control
0
 
PeterWhittsAuthor Commented:
Thanks for that but...

On tabbing through the first control which has text in, I get a rte 91 "Object variable or With Block variable not set...debug goes to ctl  = Me.ActiveControl   where Me.ActiveControl    = the text in the field and ctl = nothing?
0
 
PeterWhittsAuthor Commented:
Thats great...thanks very much

sub UpdateColour()

dim ctl as Control
Set ctl  = Me.ActiveControl

With ctl  
    If not isnull(.Value) Then
       .backcolor = -2147483643
    End If
End With

Set ctl = nothing
End Sub

Calling UpdateColour as you exit each control
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.