Format a collection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to format a group of objects other than referring to them
individually?

I want all the text boxes at a certain group level to either be bolded or
normal depending on the level of detail I am showing on the report. If I
hide the detail every line shows bolded and it is difficult to read. I'd
rather not list all 24 text boxes if I don't have to.

Thanks,

Paul
 
Paul:

Sure you can do this using the collection of controls within the section.
Here's the code you could run in your On Print event:

On Error Resume Next
Dim c As Control
For Each c In Me.Section(0).Controls
c.Properties("FontWeight") = 700 '700 = Bold, 400 = Normal
Next

Since you only want to only bold labels or text boxes, you could adjust the
code to look like this:

On Error Resume Next
Dim c As Control
For Each c In Me.Section(0).Controls 'Section 0 = the detail section
If c.ControlType = acTextBox or c.ControlType = acLabel Then _
c.Properties("FontWeight") = 700 '700 = Bold, 400 = Normal
Next

HTH
 
Looks promising, but I tried this just now.

Dim C As Control
For Each C In Me.GroupFooter0.Controls
C.Properties("FontWeight") = 400
Next

Got Runtime error 2455 "You have entered an expression that has an invalid
reference to the property Fontweight."

Paul
 
That's because all controls don't have all properties. For instance, a line
control does not have any of the font properties.
Either test the control type or use the tag property (I think every control
has a tag property.

For the controls that you want to bold/debold add a tag property of
"BoldThis" and then add a line to your code

If C.Tag="Bold" then
C.FontWeight = 700
End if

You probably need to add another condition to check if you want to set the
FontWeight to some other value or to set it to this weight.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top