Solved

VB Items in a Frame

Posted on 2003-11-17
5
247 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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now