469,281 Members | 2,450 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

Set Colour for Current Record

759 512MB
Hi again !

I have a form bound to a table.
When a control has focus the Conditional Formatting allow me to set a color for text or paper. I use that.

The question is: Is here something like that but for entire Detail section ? I use lines to separate Detail area for records. But is hard to user to locate the record. Can I set a color for the entire record (Detail section) which has the focus ?

Thank you !
Jul 10 '11 #1

✓ answered by Rabbit

You should be able to use the On Paint event of the detail section in the form. You just need a uniqueID.

For example:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Dim curID As Integer
  5.  
  6. Private Sub Detail_Paint()
  7.     If Me.ID = curID Then
  8.         Me.Detail.BackColor = 16776960
  9.     Else
  10.         Me.Detail.BackColor = 16777215
  11.     End If
  12. End Sub
  13.  
  14. Private Sub Form_Current()
  15.     curID = Nz(Me.ID, 0)
  16. End Sub

11 21969
ADezii
8,800 Expert 8TB
The following Code, when executed, will set the Backcolor of your Form's Detail Section to 1 of 16,000,000+ possible Colors:
Expand|Select|Wrap|Line Numbers
  1. Randomize
  2.  
  3. Me.Section(acDetail).BackColor = RGB(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256))
Jul 10 '11 #2
Mihail
759 512MB
Thank you for reply ADezii, but I don't understand. How this code highlight ONLY the area for current record ? I try to use your code under OnCurrent event. It work as I expect: it change the color for ALL records. Is something I missed ?
Jul 11 '11 #3
NeoPa
32,173 Expert Mod 16PB
No Mihail. It was simply that your question wasn't very easy to understand. I've changed the title now so that it should be easier.

In fact, I don't think it is possible to do that for the reasons explained in Why Values in Unbound Form Controls do not Persist.
Jul 11 '11 #4
Mihail
759 512MB
Again I must thank you, NeoPa. I'll take a look to the link you provide.
Any way, I am looking to a way to make more visible for user the current record.
Any advices ?
Jul 11 '11 #5
Rabbit
12,516 Expert Mod 8TB
You should be able to use the On Paint event of the detail section in the form. You just need a uniqueID.

For example:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Dim curID As Integer
  5.  
  6. Private Sub Detail_Paint()
  7.     If Me.ID = curID Then
  8.         Me.Detail.BackColor = 16776960
  9.     Else
  10.         Me.Detail.BackColor = 16777215
  11.     End If
  12. End Sub
  13.  
  14. Private Sub Form_Current()
  15.     curID = Nz(Me.ID, 0)
  16. End Sub
Jul 11 '11 #6
Mihail
759 512MB
It's cool Rabbit ! Works fine. Thank you very much !
Jul 11 '11 #7
NeoPa
32,173 Expert Mod 16PB
I was planning to post saying how that wouldn't work as expected.

Now Mihail has responded I'm very glad I didn't. I should have known better anyway (although I tend to think of your cleverness being mostly SQL skills). I guess from this I can take it that the paint event fires for each record as it is sent to the screen.

This is actually very interesting as it even triggers a rethink for many of the previous ideas held about what's possible on continuous forms. Very nice again Rabbit.
Jul 12 '11 #8
Rabbit
12,516 Expert Mod 8TB
I didn't think there was a way to do this either until I reexamined the events available.

It seems to trigger for every frame because the screen updates as soon as I update the code.
Jul 12 '11 #9
NeoPa
32,173 Expert Mod 16PB
It's a new event introduced in Access 2007 to support a different way of displaying forms (which possibly explains why I had never come across it before).

Unusually, the MSDN info on when the event occurs (="when the section is redrawn") is utterly useless (IMHO). There appears to be nothing easily findable elsewhere either to help understand the circumstances under which this event occurs. I'm guessing, from what you and others have posted, that it is more frequent than simply once for each record shown, but even that is unclear.
Jul 12 '11 #10
TheSmileyCoder
2,321 Expert Mod 2GB
The Paint event happens quite often, and one should be careful in its use, as it can cause a bit of screen flicker. But its also very nice to play with in terms of user interface.

In the example below, you can see how I use it to colour the current record, as well as give the currently selected "cell" a border color.

Attached Images
File Type: jpg PaintExample.jpg (70.0 KB, 6589 views)
Aug 18 '15 #11
NeoPa
32,173 Expert Mod 16PB
Nice :-)
Aug 19 '15 #12

Post your reply

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

Similar topics

reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.