Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Looping through controls on a report 1

Status
Not open for further replies.

neemi

Programmer
May 14, 2002
519
GB
Access 2000.

I was wondering if someone can point me in the right direction.

I have created a letter template in access using a form where a user can enter the text they require on a report. I am also going to create a section where they can select the font, and font size the require the text on the report to appear in.

I know I need to loop through all the controls on the report to set their requirements but I am a little stuck.

I was told that their is a "For Each" Loop I need to use to loop through these controls and make the settings but I can't find help on this anywhere. Does it exist? How do I use it?

Is there a better way anyone can suggest I achieve what I want?

Please help.

Been stuck on this prob for a while.

Cheers in advance

neemi
 
The following code snippet will loop through all the controls. Depending on the type of control it will set properties - labels will have a blue backcolor, textboxes will be red. There are lots of different control types - hit F1 while positioned over acLabel to see the list. The properties/methods of each individual control will not be listed in the IntelliSense, as the Control object is a generic object, however you can use all of the available properties but you will need to know the name. For example, each control will have a Name property, but only acLabel will have a Caption property. Neither will be displayed in IntelliSense.

Code:
Dim C As Control
For Each C In Report.Controls
    With C
        Select Case .ControlType
        Case acLabel:
            .BackColor = vbBlue
            .ForeColor = vbWhite
        Case acTextBox:
            .BackColor = vbRed
            .ForeColor = vbWhite
        End Select
    End With
Next C
 
Norris68, I knew how to loop through controls, but you get a star for the F1 tip for lists of things not stored in Intellisense!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top