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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refer to report detail section textboxes in VBA 1

Status
Not open for further replies.

roalfe

Programmer
Jun 14, 2012
1
US
Using Access 2003 VBA, I have a report using some 57 bound and calculated fields.

Client wants any field that is not equal to Zero to print in red.

In the Detail On Print event of the report, I need to loop through the textbox controls of the Detail Section.

How do I refer to this report's Detail Section textboxes?

Current code below changes all txtboxes to red (as far as I could get)
Dim db As DAO.Database
Dim ctl As DAO.Control
Dim fld As DAO.Field
Dim prp As DAO.Property

Set db = CurrentDb()
For Each ctl In Me.Detail.Controls

With ctl
Select Case .ControlType
Case acTextBox
.ForeColor = vbRed
End Select
End With
 
It does not require any code.
In design mode select the control and set conditional format (fietd value is, =0, => text is red). It can also be done for other controls in section too (formula is, [OtherFieldName]=0. => text is red).

combo
 
You can also do this without code and without conditional formatting by simply setting the Format Property to something like:
Code:
$#,##0.00[Red];($#,##0.00)[Red];0.00[Black];

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top