code help

gbanks

Registered User.
Local time
Today, 10:31
Joined
Feb 9, 2000
Messages
161
I use the code below to change the backcolor off all the text boxes on a form to the color white if the record is a new record. This works great except now they want one text box called Select_form on the form to not turn white. Is there a way to modify the code below to do this? Can the textbox called Select_form be excluded? Thanks.....

If Me.NewRecord Then
For Each ctl In Me.Controls

If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.BackColor = 16777215
End If
 
After you set all the controls to white, just set that one control back to grey, or whatever colour you like.
 
Can the textbox called Select_form be excluded? Thanks.....
Code:
   If Me.NewRecord Then
      For Each ctl In Me.Controls
         If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then 
             If ctl.Name<>"Select_form" Then
                ctl.BackColor = 16777215
             End If
         End If
        ...

An alternaltive is to use the Controls "Tag" Property and set a value that states whether or not you are to change the controls background color to White.
 
Code:
If Me.NewRecord Then
      For Each ctl In Me.Controls
          If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then 
               ctl.BackColor = 16777215
               Me.Select_form.BackColor = -2147483648
          End If
End If

-2147483648; use what ever color you wish in place of it.

*You posted it without an "End If"
________
Buy Vapor Genie
 
Last edited:
Thanks, Anthony, for the code example of the solution I posted!! ;)
 
Anthony, also, move the greying line from the loop - no need to set the BackColor as many times as there is controls.
 

Users who are viewing this thread

Back
Top Bottom