Text Box formatting based on data

  • Thread starter Thread starter CSDunn
  • Start date Start date
C

CSDunn

Hello,
I have about 200 text boxes on an Access 2000 Report that need to have a
black background if the data in the text box is 'X'.

Is there a way I could create one procedure that might work with the
Report_Open event of the Report (or some other event) that would meet this
need for the fields I need to address? I would need something that would set
the background to black if any text box had an 'X' in it, and something that
would do the same but address specific text boxes (just in case I need to go
one way or the other).

All of the text boxes are bound to database fields.

Thanks for your help!

CSDunn
 
CSDunn said:
I have about 200 text boxes on an Access 2000 Report that need to have a
black background if the data in the text box is 'X'.

Is there a way I could create one procedure that might work with the
Report_Open event of the Report (or some other event) that would meet this
need for the fields I need to address? I would need something that would set
the background to black if any text box had an 'X' in it, and something that
would do the same but address specific text boxes (just in case I need to go
one way or the other).

All of the text boxes are bound to database fields.


Use code in the Format or Print event of the section
containing the text boxes. If the text boxes are named
something like txt1, txt2, txt3, etc, then the code would
be:

For intK = 1 to 200
With Me("txt" & intK)
If .Value = "X" Then
Me("txt" & intK).BackColor = vbBlack
Else
Me("txt" & intK).BackColor = vbWhite
End If
End With
Next intK
 
Thanks for your help, I will try this.

CSDunn

Marshall Barton said:
Use code in the Format or Print event of the section
containing the text boxes. If the text boxes are named
something like txt1, txt2, txt3, etc, then the code would
be:

For intK = 1 to 200
With Me("txt" & intK)
If .Value = "X" Then
Me("txt" & intK).BackColor = vbBlack
Else
Me("txt" & intK).BackColor = vbWhite
End If
End With
Next intK
 
This procedure in the Print event of the Detail section works for me to set
the Backcolor (and corresponding ForeColor) for every Text Box in the Detail
Section. Obviously, if you only want this for specific text boxes, it'll be
a little more work... setting/testing the Tag property for the specific
controls you want would seem to be about the easiest, if you aren't using
the Tag property for some other purpose.

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim ctl As Control
Dim sec As Section
Set sec = Me.Detail
For Each ctl In sec.Controls
If ctl.ControlType = acTextBox Then
If ctl.Value < 2 Then
ctl.BackColor = 0
ctl.ForeColor = 16777215
Else
ctl.BackColor = 16777215
ctl.ForeColor = 0
End If
End If
Next
Set sec = Nothing
End Sub
 
Back
Top