473,388 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Alternate Back Colour working strangely

alternate_back_colour_problem.png

Hi all, another day another query!

I have made a report based on a query that produces a list of all the files that have been added to the database since the last report was produced. The files have been stored away in boxes in real life. The problem is with the alternate back color of the detail. I was hoping it would alternate each row of the report, however it alternates each row in each box and resets to the original back colour for a new box (make sense?)

Aka (see attachment) I was hoping it would go white, grey, white, grey etc. for the whole document but instead it goes:
Box 16 white, grey, white, grey
Box 17 white
Box 18 white, grey

I'm hoping there's a simple fix but all help is appreciated!
Jan 13 '15 #1

✓ answered by jforbes

It's not really that hard to control this yourself. Here is some example code that alternates color every time the GroupHeader is printed:

Put this Global declaration at the top of the Report Module:
Expand|Select|Wrap|Line Numbers
  1. Private iCount As Long
This fires off the Paint Event of a Group Header. This doesn't seem to work in the Group OnFormat; I'm not sure why, but I haven't really cared enough to find out either.
Expand|Select|Wrap|Line Numbers
  1. Private Sub GroupHeader0_Paint()
  2.  
  3.     Dim lColor As Long
  4.  
  5.     iCount = iCount + 1    
  6.     If iCount Mod 2 = 0 Then
  7.         lColor = -2147483604
  8.     Else
  9.         lColor = vbWhite
  10.     End If
  11.  
  12.     ' Set you Control's Background color here...
  13.     Me.FirstField.BackColor = lColor
  14.     Me.SecondField.BackColor = lColor
  15.  
  16. End Sub

11 1597
twinnyfo
3,653 Expert Mod 2GB
David,

Underfortunately, that is how the Alternate coloring works....
Jan 13 '15 #2
jforbes
1,107 Expert 1GB
It's not really that hard to control this yourself. Here is some example code that alternates color every time the GroupHeader is printed:

Put this Global declaration at the top of the Report Module:
Expand|Select|Wrap|Line Numbers
  1. Private iCount As Long
This fires off the Paint Event of a Group Header. This doesn't seem to work in the Group OnFormat; I'm not sure why, but I haven't really cared enough to find out either.
Expand|Select|Wrap|Line Numbers
  1. Private Sub GroupHeader0_Paint()
  2.  
  3.     Dim lColor As Long
  4.  
  5.     iCount = iCount + 1    
  6.     If iCount Mod 2 = 0 Then
  7.         lColor = -2147483604
  8.     Else
  9.         lColor = vbWhite
  10.     End If
  11.  
  12.     ' Set you Control's Background color here...
  13.     Me.FirstField.BackColor = lColor
  14.     Me.SecondField.BackColor = lColor
  15.  
  16. End Sub
Jan 13 '15 #3
I tried putting this in the group header paint section as you said but it didn't work. After trying it in a few places, it finally worked in the Detail_Format event but it works perfectly now. Thanks for all your help again, this forum is the best!
Jan 14 '15 #4
Sorry to revive an old thread but it's directly related to the code and question above. Is there a way to do this alternation but ensure that it counts from the bottom upwards? I need the final record on the page to be the alternate colour and then alternate up the page. I'm not sure it will work because I assume it does the formatting of the report going down the page.
Feb 11 '15 #5
jforbes
1,107 Expert 1GB
I don't think it would be that difficult. The trick would be to initialize the iCount variable as an odd or even number (0 or 1) to begin with. Probably with a DCount() of the Reports recordset and WhereClause. The WhereClause would be key.

Actually, you could probably cheat and just initialize the iCount to the DCount() of records and it would work itself out.
Feb 11 '15 #6
I am probably misunderstanding this, but wouldn't the DCount count all of the records that are being produced for the query and not just the ones that are going to fit on each page of the report?
Feb 12 '15 #7
jforbes
1,107 Expert 1GB
Ah, shoot. I got myself mixed up with another, similar, question.

I haven't figured out how to count how many records are on the page as long as the CanGrow Property is being used; Access' painting process becomes a little unreliable with the CanGrow Property.

If you aren't using the CanGrow Property, then you should be able to reset the iCount variable on a Page Header OnFormat. And since the Detail Records will be the same size, you should be able to set the iCount variable to an Odd or Even to give you the correct alternating scheme.

You might want to do this even if you have the CanGrow Property set to On, so that each page always starts out with the same background color. I don't do this as I like to see the continuity over the pages; for us it is just another visual check that everything is in order.
Feb 12 '15 #8
I'm still a bit lost with this all I'm afraid. I'm not using the CanGrow property. In my mind, I think I need the procedure to go like this:

Populate page 1 of report -> count number of records on page -> format backcolour of records based on how many records on the page -> Move to page 2 -> reset counter -> populate page 2 etc.

I understand resetting the iCount variable to 0 in each page header - makes sense so you can then work out how many records are on the page.
Feb 12 '15 #9
Would there be a way to use the page footer to determine the background colour of the last record and then, if it's the wrong colour, reformat the detail again by starting from the iCount being 1 instead of 0?
Feb 12 '15 #10
jforbes
1,107 Expert 1GB
Both of these processes sound good and logical, but they both would require either looking ahead to the end of the page (when at the top of the page) or going backwards to the top of the page after the bottom of the page has been reached. Neither of these options are available. Or al teast that I know of.

It might be easiest to look at this as a Forward-Only Recordset. While moving through it, nothing in the past can be modified and the future is not visible. So when a new page is reached, the Report would need to predict what is going to happen. This is where doing a DLookup on the Page Header to reset the iCount to a value that would, after the rest of the page is formatted, give you the backcolor that is desired.

A quick and dirty test would to set iCount to 0 for your PageHeaderSection_Format() and see what happens. Then set iCount to 1 to see what happens. Who know, maybe this is all you need.
Feb 12 '15 #11
Ah if it goes forward only then it appears I will be stuck. Many thanks for the help as always!
Feb 13 '15 #12

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

Similar topics

1
by: Joe User | last post by:
I have a set of web pages on an AD-authenticated web site that are supposed to allow users to modify their own AD account attributes, limited of course to things like their email address, URL, etc....
7
by: Matt B | last post by:
I have a need to alternate output row colour where not every row in the sequence is output, so I cannot base the colour on whether position() is odd or even. e.g. .... <xsl:for-each...
3
by: Tim Marshall | last post by:
I would swear that when I developed in A97, I could change the back colour of a form. However, in Windows XP, on both A97 and A2003, there no longer is a property showing in the format tab for...
9
by: Bazza Formez | last post by:
Hi there, For some reason, when I edit row in my datagrid, some columns have (an unwanted) back color of yellow, while others correctly display with white back color. I can see no setting in...
4
by: sconeek | last post by:
Hi all, I am generating a html based table with multiple rows of data coming in real time from a postgres DB. The underlying technology is java based however the front end is html. now i am...
2
by: Fuard | last post by:
I am trying to give back color for text box in a sub form. It changes the color while in the designing mode but not in the running mode
0
by: priyamtop | last post by:
How to give back color to label in mobile web applications
2
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Does anybody know of any examples on how to set both the row colour and the alternate row colour of a datagrid in code? I need to do this at runtime, probably in the page load event or something...
1
by: MindofZiggi | last post by:
Hi, How can I change the BackColor of a row in am ASP.NET dataGrid using a VB Function. My data table in not data bound but I do populate it from a function, it has 4 columns (Title, upload...
4
by: mustangarcher | last post by:
Hello. I do not have any code associated with this problem. This is a property setting in the detail section of some datasheet forms. I have 9 datasheet forms in my database. All of them have the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.