473,803 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Match sub-report backcolor to alternating row color in main report

63 New Member
In Access 2007, I have a report with a sub-report in the Detail section. The Detail section of the main report has alternating colors for each row displayed.

Is there a way to get the sub-report to automatically synchronize its background color with the Detail section in the parent report for each row?

Thanks in advance!
Nov 3 '08 #1
11 8026
puppydogbuddy
1,923 Recognized Expert Top Contributor
Off the top of my head (not tested), try this in the print or format events of the subreport:

Expand|Select|Wrap|Line Numbers
  1. Me.Section(acDetail).BackColor = Me.Parent.Section(acDetail).BackColor
If the above does not work, then try the following, which has been adapted from a tip provided on the web site of www.aadconsulting.com

1. Placing the subreport in design view, the BackStyle of all record Textboxes in the detail section should be set to Transparent.

2. Declare constants for your colors in the Declarations of the Subreport's module:
As an example, using the color constants below, the Subreport will display a white background for odd records and a light gray background color for even records.

3. Add the following code to the Subreport's Detail section OnFormat Event:

Expand|Select|Wrap|Line Numbers
  1. Const vbLightGrey = 12632256 
  2.  
  3.  
  4. If Me.CurrentRecord Mod 2 = 0 Then
  5. Me.Section(acDetail).BackColor = vbLightGrey   'for even records
  6. Else
  7. Me.Section(acDetail).BackColor = vbWhite         'for odd records
  8. End If 
Nov 3 '08 #2
postman
63 New Member
Thanks for replying! Unfortunately, I could not get either suggestion to work.

The On Format or On Print events wouldn't even trigger when the report was opened.

When referring to the "BackColor" property of the parent Detail section, will it retrieve the actual BackColor, or the preset BackColor (in the Detail section's properties page)?
Nov 4 '08 #3
puppydogbuddy
1,923 Recognized Expert Top Contributor
Please provide details of what "didn't work" means...error messages,etc. so that I can adjust the code accordingly. Thanks.
Nov 4 '08 #4
puppydogbuddy
1,923 Recognized Expert Top Contributor
PS:
Try changing line 4 of the above code from:

If Me.CurrentRecor d Mod 2 = 0 Then

to this:

If Me.Parent.Curre ntRecord Mod 2 = 0 Then


Let me know if there is any different result.
Nov 4 '08 #5
postman
63 New Member
I didn't get a different result, but I think it's because the OnFormat event isn't firing when I open the form. There's no error, just nothing is changing with the colors.

I tried putting the code into the OnPaint event--to make sure it was working--and it did work, sort of. The first row of the sub-report list shows gray on every record, then white for the rest of it. I attached an example showing an alternate row with the subform displayed (next to "Additional ").

Any idea why the OnFormat isn't firing?

Thanks!
Attached Images
File Type: png subformexample.PNG (1.2 KB, 381 views)
Nov 4 '08 #6
puppydogbuddy
1,923 Recognized Expert Top Contributor
As to why the OnFormat is not firing, check the property sheet and verify that the words "Event Procedure" are shown for the FormatEvent.

Here is something else to try. The above code was placed behind the subreport, and attempted to reference the parent report property. Try placing the code below behind the Main report and, as you can see, it references the subreport. Replace "YourSubrep ort" with the actual name of your Subreport and see if it works. If you get an error on the reference to .Report, leave it out of the expression:
Expand|Select|Wrap|Line Numbers
  1. Const vbLightGrey = 12632256  
  2.  
  3.  
  4. If Me.CurrentRecord Mod 2 = 0 Then            'me used here is the Main report 
  5. Me.YourSubreport.Report.Section(acDetail).BackColor = vbLightGrey   'for even records 
  6. Else 
  7. Me.YourSubreport.Report.Section(acDetail).BackColor = vbWhite         'for odd records 
  8. End If  
  9.  
Nov 5 '08 #7
postman
63 New Member
As to why the OnFormat is not firing, check the property sheet and verify that the words "Event Procedure" are shown for the FormatEvent.
I double-checked and "Event Procedure" is showing there.

I tried your code modification in the OnPaint event to make sure it fired and got the same results as shown before.

If it did work though, would it pull the ACTUAL backcolor of the row, or just the backcolor specified in the detail section's property sheet?

I'm open to more ideas. Too bad there wasn't just a "Transparen t" option for the subreport....

Thanks!
Nov 5 '08 #8
puppydogbuddy
1,923 Recognized Expert Top Contributor
I double-checked and "Event Procedure" is showing there.

I tried your code modification in the OnPaint event to make sure it fired and got the same results as shown before.

If it did work though, would it pull the ACTUAL backcolor of the row, or just the backcolor specified in the detail section's property sheet?

I'm open to more ideas. Too bad there wasn't just a "Transparen t" option for the subreport....

Thanks!
It should pull the actual backColor of the row. Let's try this:
Place an unbound textbox in the detail section of the main report. Name it txtRunningSum and set its control source to: = 1 and set its RunningSum property to "OverAll". Set its visible property to no. Finally, set its BacKStyle property to transparent as was done for the other textboxes and labels in the detail section.

Use this code in the detail section's onFormat event in place of what you had before:
Expand|Select|Wrap|Line Numbers
  1. Dim x as Integer
  2. Me.Detail.BackColor = vbWhite
  3. x = Me.txtRunningSum mod 2
  4. If x = 0 Then
  5.     Me.Detail.BackColor = vbLightGrey     'or whatever color you want
  6. End If
_______________ ________

now place this code in the subreport's OnFormat event:
Expand|Select|Wrap|Line Numbers
  1. Dim z As Integer
  2. Me.Detail.BackColor = vbWhite
  3. z= Me.Parent.txtRunningSum mod 2
  4. If z = 0 Then
  5.     Me.Detail.BackColor = vbLightGrey     'or whatever color you want
  6. End If
Whether the above code works or not depends on the whether the main report's or the subreport's onFormat event fires first. If the main fires first, it should work. If the subreport fires first, let me know and I will modify accordingly.
Nov 6 '08 #9
postman
63 New Member
Well, it worked, but only in Print Preview mode.

Your previous code worked also in Print Preview mode:
Expand|Select|Wrap|Line Numbers
  1. If Me.Parent.CurrentRecord Mod 2 = 0 Then
  2.     Me.Section(acDetail).BackColor = vbLightGrey   'for even records
  3. Else
  4.     Me.Section(acDetail).BackColor = vbWhite         'for odd records
  5. End If
(in the subreport Detail section's onFormat event)

The OnFormat event would not fire if the report was opened in the "Report View" mode--which is often how the report is opened in the app I'm working on. It would only fire if I opened the report in Print Preview mode.

I tested it by putting a MsgBox in both sets of code with a message identifying whether it was the main or the sub report. Both events would fire when opened in Print Preview mode.


So now, I need to figure that out...but that's probably a whole separate issue.
Nov 6 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2037
by: Matthew Rees-George | last post by:
I want this example xml:- <xxx>text before <yyy att="value"/> text in the middle <zzz>ignored but transformed</zzz> text after</xxx> To be transformed to this:- text before value text in the middle 'found a zzz' text after I.e. the text positions must be preserved, but the element(s) must be transformed.
0
346
by: Rui Macdonald | last post by:
I working with some samples from angGoGo PhotoControl and when I start it I receive always the following message, can you help me please? :-( -------------------- The located assembly's manifest definition with name 'System' does not match the assembly reference. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it...
1
1461
by: larry | last post by:
I'm having trouble with a pattern match expression using regex. I need to have the first 4 characters as letters and the next 2 characters as digits. ex... PROJ12 - when trying "\D{4}\d{2}" as the expression string.. it does not work on the .ismatch function when i enter "proj12" into a text box. What is the problem here?
2
3556
by: Hugo Ferreira | last post by:
Hi! I'm trying to do a search-replace in places where some groups are optional... Here's an example: ('ola', None) ('ola', '') ('ola', 'ole')
1
6924
by: smoi | last post by:
I have two listbox in my Form, one call lstFolders, the other one call lstFiles. I have the functions below: Private Sub lstFolders_DblClick() 'Call FunctionToListFilesInThisFolder End Sub Private Sub lstFiles_DblClick()
6
16965
by: Brisokol | last post by:
I created a db which works fine in Access 2000 on Win2k, but those who have Access 2003 and XP (and Vista!), get errors running event procedures on a particular form: The error looks like this: "The Expression On Load you entered as the Event Property Setting produced the following error: The Procedure Declaration Does not Match Description of Event or Procedure having the same name." The same errror comes up for all events called on...
4
6287
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Dim dInfo As DirectoryInfo dInfo = New DirectoryInfo(Server.MapPath("/Folder1")) dgFD.DataSource = dInfo.GetFiles("*.*") dgFD.DataBind() End Sub
3
11164
by: Christoph Krammer | last post by:
Hello everybody, I wanted to use re.sub to strip all HTML tags out of a given string. I learned that there are better ways to do this without the re module, but I would like to know why my code is not working. I use the following: def stripHtml(source): source = re.sub("", " ", source) source = re.sub("<.*?>", "", source, re.S | re.I | re.M)
4
1952
by: MRe | last post by:
Hi, Is it possible using XSLT to transform this.. <test> <b>0</b> <a>1</a> <a>2</a> <b>3</b> <b>4</b>
1
5499
by: mfaisalwarraich | last post by:
Hello, I am trying to match the values of a combo box which are typed inside a combo box with the comb box items, which are bind to a datasource. i can see the items in the combo box and if i get the selecteditem its working fine means nothing is wrong with the connection and other things. but when im trying to match the values im getting this error: System.Data.DataRowView and this error continues to display equal to the number of...
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10550
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.