Problem with Formatting code

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

CSDunn

Hello,
In my report, the following code sets the BackColor value of any acTextBox =
0 If the value in the TextBox = 'X':

Private Sub FormHeader_Format(Cancel As Integer, FormatCount As Integer)
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Value = "X" Then ctl.BackColor = 0
End If
Next ctl
End Sub

The problem is, once an instance of the report is found to have an 'X' in a
given TextBox, the same TextBox in every other instance of that report will
have the BackColor value set to zero whether or not the value in the TextBox
= 'X' for those other instances.

How can I change the above code so that if the ctl.Value <> "X", the
ctl.BackColor will not be changed?

Thanks for your help!

CSDunn
 
CSDunn said:
Hello,
In my report, the following code sets the BackColor value of any acTextBox =
0 If the value in the TextBox = 'X':

Private Sub FormHeader_Format(Cancel As Integer, FormatCount As Integer)
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Value = "X" Then ctl.BackColor = 0
End If
Next ctl
End Sub

The problem is, once an instance of the report is found to have an 'X' in a
given TextBox, the same TextBox in every other instance of that report will
have the BackColor value set to zero whether or not the value in the TextBox
= 'X' for those other instances.

How can I change the above code so that if the ctl.Value <> "X", the
ctl.BackColor will not be changed?

Thanks for your help!

CSDunn
CS,
If you turn the color on, you then have to turn it off when the
critreria is not met.

Private Sub FormHeader_Format(Cancel As Integer, FormatCount As Integer)
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Value = "X" Then
ctl.BackColor = 0
Else
ctl.BackColor = vbWhite
End If
Next ctl
End Sub
 
Back
Top