We help IT Professionals succeed at work.

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

PeterWhitts
PeterWhitts asked
on
Medium Priority
222 Views
Last Modified: 2012-05-05
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
Comment
Watch Question

Leigh PurvisDatabase Developer
CERTIFIED EXPERT

Commented:
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

Author

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?
Database Developer
CERTIFIED EXPERT
Commented:
Doh - damn air code...

Set ctl  = Me.ActiveControl
 ^---------- vital

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.