Set Colour for Current Record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mihail
    Contributor
    • Apr 2011
    • 759

    Set Colour for Current Record

    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 !
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    The following Code, when executed, will set the Backcolor of your Form's Detail Section to 1 of 16,000,000+ possible Colors:
    Code:
    Randomize
    
    Me.Section(acDetail).BackColor = RGB(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256))

    Comment

    • Mihail
      Contributor
      • Apr 2011
      • 759

      #3
      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 ?

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        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.

        Comment

        • Mihail
          Contributor
          • Apr 2011
          • 759

          #5
          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 ?

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

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

            For example:
            Code:
            Option Compare Database
            Option Explicit
            
            Dim curID As Integer
            
            Private Sub Detail_Paint()
                If Me.ID = curID Then
                    Me.Detail.BackColor = 16776960
                Else
                    Me.Detail.BackColor = 16777215
                End If
            End Sub
            
            Private Sub Form_Current()
                curID = Nz(Me.ID, 0)
            End Sub

            Comment

            • Mihail
              Contributor
              • Apr 2011
              • 759

              #7
              It's cool Rabbit ! Works fine. Thank you very much !

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #8
                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.

                Comment

                • Rabbit
                  Recognized Expert MVP
                  • Jan 2007
                  • 12517

                  #9
                  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.

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    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.
                    Last edited by NeoPa; Dec 27 '11, 03:33 AM. Reason: Typo

                    Comment

                    • TheSmileyCoder
                      Recognized Expert Moderator Top Contributor
                      • Dec 2009
                      • 2322

                      #11
                      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.
                      [IMGnothumb]http://bytes.com/attachments/attachment/8426d1439883317/paintexample.jp g[/IMGnothumb]
                      Attached Files

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32633

                        #12
                        Nice :-)

                        Comment

                        Working...