Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB Items in a Frame

Posted on 2003-11-17
5
Medium Priority
?
296 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 200 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 100 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 100 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans

730 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