Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing backcolor with code

Status
Not open for further replies.

EddyLLC

Technical User
Mar 15, 2005
304
US
Using the function below called from a form I trying to change the backcolor of controls if not empty. The code runs without errors but does nothing to the backcolor. The controls are enabled. Thanks for the help.


Function Shade(strForm As Form)
For Each ctl In strForm.Controls
If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
If IsNull(ctl) Or ctl.Value = "0" Or Trim(ctl.Value) = "" Then
Set ctl.BackColor = &H8000000F
Else: ctl.BackColor = &HFFFF&
End If
Else: End If
Next ctl

End Function
 
I think you can work this into what you want...
[tt]
Option Explicit

Private Sub
Command1_Click()
Dim C As Control

For Each C In Me.Controls
If TypeOf C Is TextBox Or TypeOf C Is ComboBox Then
If
Trim(C.Text) <> vbNullString Then C.BackColor = vbRed
End If
Next C
End Sub
[/tt]



Good Luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top