Solved

VB Items in a Frame

Posted on 2003-11-17
5
274 Views
Last Modified: 2010-04-17
Hi.

Is there a way to change a common property at runtime for all the items in a frame or form?

i.e.
For each THING in thisFORM
      THING.BackColor = vbWhite
Next THING

OR for a Frame?

Cheers  

Sheepie
0
Comment
Question by:SheepDip
5 Comments
 

Accepted Solution

by:
kapil_mohta earned 50 total points
ID: 9762991

It's exactlly the way you think :

Dim ctrl As Control

For Each ctrl In Me.Controls
    ctrl.BackColor = vbRed
Next

Kapil
0
 
LVL 14

Assisted Solution

by:Thandava Vallepalli
Thandava Vallepalli earned 25 total points
ID: 9763012
Hello,

Place 5 textboxes and 1 command button in the form.  And place the code in code window.

===========================
Private Sub Command1_Click()
    Dim ctrl As Control
    For Each ctrl In Form1.Controls
        ctrl.FontBold = True
    Next ctrl
End Sub
===========================

Now run the form. Press the button all the controls in the form text becomes bold.

So here is the syntax to access all the controls in the form

"form_name.Controls" will return collection of all the controls

All the best,
V.Thandava Krishna.
0
 
LVL 43

Assisted Solution

by:TimCottee
TimCottee earned 25 total points
ID: 9763099
Hi SheepDip,

For controls in a form this is as kapil_mohta suggests. However as a frame has no .controls collection and all controls placed on it are actually part of the form's .controls collection you need to check whether the control is contained in the frame or not:

For Each Ctrl In Me.Controls
  If Ctrl.Container Is Frame1 Then 'Check whether the control is contained in the frame
    'Do something with it
  End If
Next

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 

Author Comment

by:SheepDip
ID: 9763288
Thks all.

Kept getting an error as certain objects did not have the backcolor property (and i couldn't be arsed finding out which ones - there are a lot). So dropped in the dreaded catch all on error resume next.

     For Each ctrlA In frmTicket.Controls ' Change ticket colour = SELL
            On Error Resume Next
            ctrlA.BackColor = &HC0C0FF
      Next ctrlA
      On error goto 0
 
cheers again

SD
0
 

Expert Comment

by:kapil_mohta
ID: 9777256
To know the control type , you can use : typeof

i.e.
For Each ctrl In Me.Controls
    if typeof ctrl is textbox then ' say
        ctrl.BackColor = vbRed
    endif
Next

Kapil
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This is about my first experience with programming Arduino.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question