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
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi, welcome to the board.

Try:

Code:
Private Sub Frame1_Enter()
    Frame1.BackColor = 12
    Frame2.BackColor = -2147483633
End Sub
 
Private Sub Frame2_Enter()
    Frame2.BackColor = 3
    Frame1.BackColor = -2147483633
End Sub

-2147483633 is the default lovely grey colour userforms have. Mess around with the colours to get what you want.
 
Upvote 0
Hi Hari - vba has a userform property called activecontrol, so you could check me.activecontrol.name
If it's set to any of the first textbox names then set the first frame colour and unset the second, and vice versa......

Good luck
 
Upvote 0
Try this:- For each Textboxes in each frame, place code as below altered to suit particular TextBox
When you click a particular Text Box, Its Frame Backcolor will Change to "Red" .
Code:
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
call Frcol (ActiveControl)
End Sub

Create a Module with sub below,Alter Userform Name to suit.

Code:
Sub Frcol(nam As Control)
Dim ctrl As Control
For Each ctrl In UserForm4.Controls
If TypeName(ctrl) = "Frame" Then
    If ctrl.Name = nam.Name Then
        ctrl.BackColor = RGB(205, 0, 0)
    Else
        ctrl.BackColor = RGB(205, 205, 205)
    End If
End If
Next ctrl
End sub
Regards Mick
 
Last edited:
Upvote 0
I get what MickG is trying to tell.
which is what I was doing, but is there no other way to do this without going thru all the text boxes?I have like 7 text boxes per frame and 4 frames on the form.

Could you give me more information on active control and how to use it?

Thank you very much for all the quick replies.
 
Upvote 0
I don't think there is a simpler way of doing this, and this code does uses the "Active control".
Youv'e just got to paste into each Textbox control, Just 28 times !!!
Mick
 
Upvote 0
I'm not going to argue with MickG's solution, as he is some sort of Excel God, but did you consider my reponse? It seems to work for me, and does what I think you want it to do.

If it's totally wrong then ignore me ;)
 
Upvote 0
you could assign all textboxes as members of a class, do the color changes in a class module with 1 piece of code for n textboxes. that i think is what harper86 is getting at.

jamesW i will have a try of your sln just for interest. perhaps there are other controls on the frame not mentioned, which he does not want to allow to initiate a color change?
 
Upvote 0
I Had a link to a "Class Module" that Andrew Poulson posted, for this sort of thing. If I can find it I'll post back.
Mick
 
Upvote 0

Forum statistics

Threads
1,215,426
Messages
6,124,828
Members
449,190
Latest member
rscraig11

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