Frames question

harper86

New Member
Joined
Nov 25, 2010
Messages
14
Hey
So I have a frame with 5 or 6 text boxes.
Right below this I have another frame with 5 or 6 more text boxes.
The thing I want to do is, if you are entering any text in any of the 5 or 6 text boxes the frame should change its background color to say red. Now if you go to the next frame the 1st frames bg color should go back to the original bg color and the second frames bg color should now be red.

This should also be true when you go back to frame 1.

Is there anyway to do this?

Also is there any way to change the bg color of the frame as soon as the text box becomes tabbed, like you have not input anything but the text box is selected.

Thank you very much
Hari
 
why change the background? but yes i think _enter is best

the label will hilite the checkbox is active anyway
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Yup that def works setting the label to visible and invisible works like a charm..
Thank you very much everybody, I really appreciate it..
 
Upvote 0
Hi, To anyone who may be interested, this is a modified version of some Mike Rickson's code.
Create a class Module and change its name to "TBColor".
Open the Module and paste the following code:-
Then Paste the Userform Code, as shown below.

Code results:- When any TextBox is clicked, its Background colour changes to "Yellow".
NB:- In Colin's code if you change the "Change" Event to a "MouseDown Event, The Frame color will change on "Selection" rather than "Change."
NB:- Change Userform Name to suit
"Class Module code"
Code:
Public WithEvents BTB [COLOR="Navy"]As[/COLOR] MSForms.TextBox
Private [COLOR="Navy"]Sub[/COLOR] BTB_MouseDown(ByVal Button [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer,[/COLOR] ByVal Shift [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer,[/COLOR] ByVal X [COLOR="Navy"]As[/COLOR] Single, ByVal Y [COLOR="Navy"]As[/COLOR] Single)
[COLOR="Navy"]Dim[/COLOR] ctrl [COLOR="Navy"]As[/COLOR] MSForms.Control
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] ctrl [COLOR="Navy"]In[/COLOR] UserForm4.Controls
[COLOR="Navy"]If[/COLOR] TypeName(ctrl) = "TextBox" [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]If[/COLOR] ctrl.Name = BTB.Name [COLOR="Navy"]Then[/COLOR]
       ctrl.BackColor = RGB(255, 255, 0)
    [COLOR="Navy"]Else[/COLOR]
        ctrl.BackColor = RGB(255, 255, 255)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] ctrl
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
"UserformCode"
Open the userform Module and paste the following code:-
Code:
[COLOR="Navy"]Dim[/COLOR] MyBox() [COLOR="Navy"]As[/COLOR] TBColor
Private [COLOR="Navy"]Sub[/COLOR] UserForm_Initialize()
    [COLOR="Navy"]Dim[/COLOR] oneControl [COLOR="Navy"]As[/COLOR] Object, pointer [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
    ReDim MyBox(1 To Me.Controls.count)
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] oneControl [COLOR="Navy"]In[/COLOR] Me.Controls
      [COLOR="Navy"]If[/COLOR] TypeName(oneControl) = "TextBox" [COLOR="Navy"]Then[/COLOR]
            pointer = pointer + 1
            [COLOR="Navy"]Set[/COLOR] MyBox(pointer) = New TBColor
            [COLOR="Navy"]Set[/COLOR] MyBox(pointer).BTB = oneControl
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR] oneControl
    ReDim Preserve MyBox(1 To pointer)
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,216,081
Messages
6,128,696
Members
449,464
Latest member
againofsoul

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top