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

TextBox Background Color on an Access report based on another field

Status
Not open for further replies.

CSADataCruncher

Technical User
Feb 5, 2004
74
US
Dear experts,

I've searched for some conditional formatting of different items on an Access Report. Scenario#1 works perfectly (thanks to Duane's help). However, what I'm trying to accomplish now is to have the Company field/Groupheader have a gray background (I know, my test scenario is for red), if the value of the RecAdd field is 999.

As mentioned, the coding for #1 works but #2 doesn't.

Scenario#1
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Title.FontBold = IIf([RecAdd] = 999, True, False)
End Sub

Scenario#2
Private Sub GroupHeader3_Format(Cancel As Integer, FormatCount As Integer)
If [RecAdd] = 999 Then
[Company] BackColor = 255
Else
[Company] BackColor = 16777215
End If
End Sub

I've also tried including company.backcolor rather than "[Company] BackColor" and I have tried

Title.BackColor = IIf([RecAdd] = 999, 255, 16777215)

Would someone be able to help me accomplish the goal of making the Company field/groupheader have a gray background if the value of the RecAdd field is 999?

Thank you, in advance, for any help in this area.

Peggy
 
Yikes... sorry everyone, I found the problem in my coding... it was a simple case of using the wrong control name. However, I have a slightly different question....

Using

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Title.FontBold = IIf([RecAdd] = 999, True, False)
End Sub

is it possible to bold more than one field in the same formatting code? I'd like to be able to have, not only the title bold, but the name as well.

Thank you,
Peggy

 
Try:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  Me.Title.FontBold = ([RecAdd] = 999)
  Me.txtName.FontBold = ([RecAdd] = 999)
End Sub


Duane
Hook'D on Access
MS Access MVP
 
Thank you... it's still kicking me out to the debugger. I changed the code to:

Title.FontBold = ([RecAdd] = 999)
NameLbl.FontBold = ([RecAdd] = 999)

and made sure that my report controls were labeled the same. I had tried it with the "Me." in front of there before but it give me an error message based on that alone (didn't know if I was literally supposed to use that portion of the code or not).

Thank you,
Peggy
 
You must have three bound controls in the section of your report:
Title
RecAdd
NameLbl
I always use [blue]Me.[/blue] when referencing controls on forms and reports. It becomes easier for me to maintain when I go back to modify my code and see the [blue]Me.[/blue]

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

Part and Inventory Search

Sponsor

Back
Top