Setting every text object in a detail line to bold.

R

richardb

I want to set all the text objects in the detail line to bold depending on a
condition of one of those objects. For example,

If txtExpired.Text <> "Current" Then
txtExpired.FontBold = 1 : txtName.FontBold = 1 'etc.
Else: txtExpired.FontBold = 0 : txtName.FontBold = 1 'etc.
End If

My question: Is there a syntax, of the form "For all objects in detail" that
allows me to bold every text box in the detail line without setting each
FontBold to 1 individually?
 
A

Allen Browne

If this is a Continuous form or datasheet, setting the properties like that
will affect all rows (not just the current record.)

Perhaps there's another way to highlight the row, e.g. placing a text box in
the detail section behind all the others, and using Conditional Formatting
to change its BackColor.

To answer your specific question, you can loop through the text boxes and
combos in the Detail section like this:
Dim ctl As Control
For Each ctl In Me.Section(acDetail).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
Debug.Print ctl.Name
End Select
Next
 
D

Douglas J. Steele

Yes, but be aware that not all controls can be set to Bold (think lines,
check boxes, radio buttons and so on)

Dim ctl As Control

For Each ctl In Me.Sections(acDetail).Controls
Select ctl.ControlType
Case acLabel, acCommandButton, acTextBox, _
acListBox, acComboBox, acToggleButton
ctl.FontBold = True
End Select
Next ctl

I think that's the list of ones that have text. The ones I've excluded are
acRectangle, acLine, acImage, acOptionButton, acCheckBox, acOptionGroup,
acBoundObjectFrame, acSubform, acObjectFrame, acPageBreak, acPage,
acCustomControl and acTabCtl
 
R

richardb

My bad. I did not mention that this is the detail section of a report and all
of the controls are text boxes. i want specific lines of the report to bold,
depending on a value in one of the text boxes. i would place your code in the
detail on print section. I will try your code and drop a note as to results.
Many thanks...
 
R

richardb

worked like a charm!! i left out the select case, because all controls are
actextbox, but will keep your method on file. also wrapped around a little
more code to return fontbold to false when not needed and added an exit sub
escape if the need to bold has not changed since the previous line.

this is not the first time you and allen helped me; many thanks...
 

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

Top