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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing BackColor for controls 2

Status
Not open for further replies.

PaulBricker

Programmer
Sep 25, 2002
3,554
US
I already know how to change the Backcolor for a control using VBA, but this has a little twist to it. I'm going to end up with close to 150 controls on this form we are building, and I don't want to have to open Event Procedures for On_Got_Focus and On_Lost_Focus for every control inorder to change the color. I thought there might be a way to get the BackColor to change using one of the form methods but I haven't been able to find anything suitable. I'm just looking for suggestions if anyone has any.

Thanks

Paul
 
Depending on what you are doing, it may be possible to use the KeyPress event having set KeyPreview to 'Yes'
 
Try this:

Select all of the controls (shift select or whatever) and then enter =ToggleColor(True) in the OnGotFocus event. Then Select all of the controls and enter =ToggleColor(False) in the OnLostFocus event.

Then copy and paste the following function:
Code:
Function ToggleColor(bolColorOn As Boolean)

    If (bolColorOn) Then
        Screen.ActiveControl.ForeColor = 255
    Else
        Screen.ActiveControl.ForeColor = 0
    End If
    
End Function
 
How ae ya PaulBricker . . .

Have you considered [purple]Conditional Formatting?[/purple] . . . Using code you could easily setup each textbox involved.

Calvin.gif
See Ya! . . . . . .
 
Thanks everyone. They were all good suggestions. I used FancyPrairie's because I had already set up the boolean function. I just had completely forgot that I could call that function directly from the Event line. I was thinking I had to open an Event Procedure and call the function from inside each one.
Just a blonde moment I guess (I hope)[shadeshappy]

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top