473,387 Members | 1,844 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,387 software developers and data experts.

change background color if record number is odd?

AccessIdiot
493 256MB
I know this one is kind of odd. But I was wondering if it were possible to apply some kind of conditional formatting where the background color of the form changes from one record to the next. Something like odd numbers could be the standard grey and even numbers could be pink or something like that.

Is this even possible?

thanks!
Apr 9 '07 #1
14 18189
MMcCarthy
14,534 Expert Mod 8TB
I know this one is kind of odd. But I was wondering if it were possible to apply some kind of conditional formatting where the background color of the form changes from one record to the next. Something like odd numbers could be the standard grey and even numbers could be pink or something like that.

Is this even possible?

thanks!
conditional formatting will only work on active controls that contain values like textboxes. If the form is not continuous you could code something into the on current even of the form but in a continuous form it would change all the background colours each time.

Mary
Apr 10 '07 #2
pks00
280 Expert 100+
As Mary says, use the form_current

Form doesnt have a background colour though, one I think u cant set anyway, though I could be wrong :)

U could set the backcolor for Detail
eg

Expand|Select|Wrap|Line Numbers
  1. private sub Form_Current()
  2.     if me.somefield and 1 = 1 then
  3.        detail.backcolor = vbred      'odd
  4.     else
  5.        detail.backcolor = 16777215  'even
  6.     end if
  7. end sub
  8.  

But the colour u pick, u need to ensure form is still readable
u may find labels have different backgrounds as well, so it could be a case of going thru all controls that need colouring
Apr 10 '07 #3
Rabbit
12,516 Expert Mod 8TB
If you're using 2003 then:
Shading alternate rows in reports
Apr 10 '07 #4
AccessIdiot
493 256MB
As Mary says, use the form_current

Form doesnt have a background colour though, one I think u cant set anyway, though I could be wrong :)

U could set the backcolor for Detail
eg

Expand|Select|Wrap|Line Numbers
  1. private sub Form_Current()
  2.     if me.somefield and 1 = 1 then
  3.        detail.backcolor = vbred      'odd
  4.     else
  5.        detail.backcolor = 16777215  'even
  6.     end if
  7. end sub
  8.  

But the colour u pick, u need to ensure form is still readable
u may find labels have different backgrounds as well, so it could be a case of going thru all controls that need colouring
Hey could you explain that code for me a bit? I'm not sure what is meant by me.somefield - is this any textfield control on the form? And what is 1=1? What does that mean to Access?

thanks!
Apr 10 '07 #5
pks00
280 Expert 100+
ok, code was an example, based on your example of odd numbers

this is an example based on a value in your form

me.somefield refers to a control on your form
detail is the part of the form where all your controls exist

anding a numerical value with 1 is a way to check if its odd number or not


Expand|Select|Wrap|Line Numbers
  1. private sub Form_Current()
  2.  
  3.     'check if field on form called somefield is odd
  4.     if me.somefield and 1 = 1 then
  5.        detail.backcolor = vbred      'odd
  6.     else
  7.        detail.backcolor = 16777215  'even
  8.     end if
  9. end sub
  10.  
Apr 10 '07 #6
AccessIdiot
493 256MB
thanks, that's what I figured but I wanted to check if the 1=1 part referred to the value of somefield or if it was totally unrelated.
Apr 10 '07 #7
Rabbit
12,516 Expert Mod 8TB
If you're using 2003 then:
Shading alternate rows in reports
Just thought I'd point out that this link outlines the steps to do what you want to do.
Apr 10 '07 #8
AccessIdiot
493 256MB
Sorry! I meant to get back to you when I had a chance to check it out. Does it matter that I want to do this in a form and not in a report?

I'll look into it now.
Apr 10 '07 #9
Rabbit
12,516 Expert Mod 8TB
Sorry! I meant to get back to you when I had a chance to check it out. Does it matter that I want to do this in a form and not in a report?

I'll look into it now.
Oh, a form? Totally missed that.
Hmm.. maybe, you might have to use a different event though.
Apr 10 '07 #10
AccessIdiot
493 256MB
Yes I tried adapting it but I can't figure out how to make it work. :)

I tried just copying and pasting the code in, then calling it from the form_current event, but it wants parameters and I have no idea what parameters to give it!

Expand|Select|Wrap|Line Numbers
  1. Private shadeNextRow As Boolean
  2. Const shadedColor = 12632256
  3. ' Const shadedColor = 15726583 ' alternative shade colors
  4. ' Const shadedColor = 14078404
  5. ' Const shadedColor = 13356495
  6. ' Const shadedColor = 14281974
  7. Const normalColor = 16777215
  8.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2.  
  3.   On Error GoTo Detail_Format_Error
  4.  
  5. ' Choose a color based on the shadeNextRow value
  6.   If shadeNextRow = True Then
  7.     Me.Section(acDetail).BackColor = shadedColor
  8.   Else
  9.     Me.Section(acDetail).BackColor = normalColor
  10.   End If
  11.  
  12. ' Switch the color for the next row
  13.   shadeNextRow = Not shadeNextRow
  14.  
  15. Detail_Format_Exit:
  16.   Exit Sub
  17.  
  18. Detail_Format_Error:
  19.   MsgBox "Error " & Err.Number & ": " & Err.Description
  20.   Resume Detail_Format_Exit
  21. End Sub
  22.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. Call Detail_Format
  3. End Sub
Apr 10 '07 #11
ADezii
8,834 Expert 8TB
I know this one is kind of odd. But I was wondering if it were possible to apply some kind of conditional formatting where the background color of the form changes from one record to the next. Something like odd numbers could be the standard grey and even numbers could be pink or something like that.

Is this even possible?

thanks!
You could use the 'Read Only' property of a Form in its Current() Event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Me.CurrentRecord Mod 2 = 0 Then           'Even Record
  3.   Me.Section(acDetail).BackColor = QBColor(13)
  4. Else
  5.   Me.Section(acDetail).BackColor = QBColor(12)
  6. End If
  7. End Sub
Apr 10 '07 #12
AccessIdiot
493 256MB
Brilliant! That works great! Except the colors are a bit, um, extreme. I know custom colors are not easy in Access but is there a way to get away from the standard color choices?

And could you explain how the "read only" part comes in? I understand the code but am not sure what you meant by "read only".

Thanks so much! :)
melissa
Apr 11 '07 #13
ADezii
8,834 Expert 8TB
Brilliant! That works great! Except the colors are a bit, um, extreme. I know custom colors are not easy in Access but is there a way to get away from the standard color choices?

And could you explain how the "read only" part comes in? I understand the code but am not sure what you meant by "read only".

Thanks so much! :)
melissa
I apologize for the confusing information:
  1. CurrentRecord is a 'Read Only' property of a Form, meaning that it can only be read and not written to.
  2. The Color choices were of course ugly, but they were for demonstration purposes only.
  3. You can have your choice of literally 16,000,00 different colors via the RGB(red, green, blue) Function as indicated below.
Expand|Select|Wrap|Line Numbers
  1. Me.Section(acDetail).BackColor = RGB(100, 213, 4)
  2. Me.Section(acDetail).BackColor = RGB(1 - 255, 1 - 255, 1 - 255)
Place this code in the DblClick() Event of a Form's Detail Section for a simple demo:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_DblClick(Cancel As Integer)
  2.   Randomize
  3.   Me.Section(acDetail).BackColor = RGB(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256))
  4. End Sub
Apr 11 '07 #14
AccessIdiot
493 256MB
Very cool. I knew there must be a way to specify RGB rather than the number off the color palette. Thank you so much!!

:)
Apr 11 '07 #15

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

Similar topics

13
by: Gary | last post by:
I have a table with a form consisting of several checkboxes and I'm wondering if its possible to change the table row background color on mouseover or hover and make it stay that color when the...
7
by: John Baker | last post by:
Hi: I imagine there are hundreds of responses to this question, but i cant find any on the site using a search. How do you change the background color of buttons? I know there must be an easy...
4
by: Georges Heinesch | last post by:
Hi. I have a form defined as datasheet view. Can I change the background color of the individual fields (colums) separately (or all together)? If yes, how? TIA --
5
by: DavidB | last post by:
Greetings I don't know if this is possible, but this group should be able to tell me. I have a webpage with a changing message board (I understand the problems with having changing text, but...
1
by: ngpost1 | last post by:
I have a Crystal Reports.Net report being generated from my C# application. I would like to change the background color of the details section (not the text mind you) of the report on certain...
6
by: spit0033 | last post by:
I have created a vertical menu with a white background, once a link is clicked i want that menu item's background color to change. Then once another menu item is clicked the first menu items...
2
by: bucchi | last post by:
Hi, I have an input field and I have to change the background color when the contents change. The contents are changed by a pop-up. On submit of the pop-up the contents change.How can I...
1
by: Ulf Malmros | last post by:
I want to change background color in a control in a form grid depending on the value in another control in the same grid. Can anyone giv me a hint about how to do this? Please!
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.