Problem with Formatting code

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
 
F

fredg

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
 

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