Solved

VB Items in a Frame

Posted on 2003-11-17
5
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C qsort compare function issue 6 70
statistics basics sources 2 75
print bytes of an integer 6 48
Java pass by reference 3 76
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

710 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