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

Reporting - Change SubReport background color using VBA rpt open event

Status
Not open for further replies.

dlightful

Programmer
Mar 17, 2004
2
US
I want to change the background color using VBA on the fly to a subReport. I've specified the following in the main report 'Event Open procedure' but it won't work.

Private Sub Report_Open(Cancel As Integer)
me!subreport1.Report!Section(0).BackColor = vbBlue
End Sub

 
I got it to work by putting that code in the OnOpen event of the SUBreport. If you need to set it conditionally, refer to the field on the main report using the Parent object:
[bold][blue]
If Me.Parent.ID = 1 Then
Me.Section(0).BackColor = vbBlue
Else
Me.Section(0).BackColor = vbRed
End If
[/bold][/blue]
If the ID field in the parent report = 1, set the background color to blue; otherwise, set the background color to red.



[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Yes, I agree, that would work, but let me make it a little harder...

[Subreport1] does not reside as a "Reports" object. I merely created my main report by dragging and dropping several subForms from their home as "Forms" objects.

The entire report works as I intend it to, but I want to embellish the subReports (subForms) by changing their background color at report open time.

These subForms all have another life as actual subForms in a main form. I may want to change these subforms later. If I do change them, I'm trying to avoid having to apply those same changes in a seperate subReport.

Hope that's clear.

Thanks for your help.


 
Okay, you stumped me! I tried a dozen different ways, including setting a timer on the form, and couldn't get the background to change colors. Sorry.

[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top