• Highlighting the active field/record (A97/SR2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Highlighting the active field/record (A97/SR2)

    Author
    Topic
    #383655

    When moving to different text boxes on a form, I use a procedure to change the background color of the current text box. The default background color of the text boxes is white. When entering a text box, the background color changes to yellow. When exiting that text box, the background color changes back to white.

    This is accomplished with a module -> basBackColor

    Private Const conYellow = 10092543
    Private Const conWhite = 16777215

    Public Function BackgroundYellow()
    Screen.ActiveControl.BackColor = conYellow
    End Function

    Public Function BackgroundWhite()
    Screen.ActiveControl.BackColor = conWhite
    End Function

    For each text box, the property setting is:

    – Property – – – – – – – – – – – Value
    OnGotFocus ……….. =BackgroundYellow()
    OnLostFocus ………. =BackgroundWhite()

    NOTE: For the form “On Open” event, it needs to have a Me.SetFocus procedure.

    When using this method on a continuous form, ALL of the records for the control change their background color. Is there a way to change the background color of JUST the individual record of the control where the cursor is located in a continuous form?

    Thank you for any help.

    RonM

    Viewing 0 reply threads
    Author
    Replies
    • #654947

      It is possible to change the background color of the active record or some of its controls in a continuous form – see for instance Mark Liquorman’s demo, downloadable from http://www.Liquorman.net/Tips.html%5B/url%5D; look for ‘Highlight a Single Row’. Although I haven’t seen an example of highlighting the active control in the active record in a continuous form, but maybe Mark’s demo can be adapted to do that.

      • #655030

        I tried to download that file from Mark Liquormans site. It came back saying that is is unavailable.

        • #655034

          Yes, I get that too at the moment. Mark will probably read this thread, so maybe he’ll react. You might also send him a PM.

          In the meanwhile, I have attached a similar demo (based on the one by Mark).

          • #655103

            Hans

            This is by far the most deceptively simple way of highlighting a complete row, so simple I’m still trying to find out what I’m missing.

            In the real world many people using databases (the users that is) will want to have the last row highlighted when a form or subform opens as that is usually the most recent entry. Have you found a way of doing this within your routine?

            David Parton

          • #655123

            Downloaded the Highlight database. Could you tell me how the background color change happens from the txtBackground/IIF.. statement. This is something new to me. One thing I did try was to highlight out the “on current” event of the form. The result was that as you moved through the form, the current field/record was all that was highlighted – not the entire record. confused

            • #655128

              I have attached a Word document that gives step by step instructions on how to create such a form, and does a feeble attempt in explaining how it works. The “accompanying database” is the one I attached to my previous reply.

            • #655214

              There was a “typo” in my previous post. Where I said (highlight out the “on current” event… – – it should say (“comment ” out the “on current” event… Try that and see if each individual field and record is highlighted as you move through them. I do not understand what the String(……) does. The example attachment for the txtBackground Control Source contains – String(50,219), Null. What does that mean?

              Thanks for your help
              RonM

            • #655237

              In the first place, I suddenly realize that you don’t need any code or fancy tricks at all to highlight the current control. Just set the background color of the controls in the detail section to the desired highlight color, then set the background style to transparent. You must do it in that order, because setting a background color undoes the transparency. Access never displays the current control as transparent, so that control will show the “highlight” color.

              So much for complicated solutions.

              The idea behind the demo I posted is that if you format a control in a continuous form in Access 97, the format will apply to all records, so you can’t use that to highlight the current record or control. The only things that can look different from record to record are those that depend on the record source of the form. The trick is to create a text box that acts as background to the detail section and fill it with box characters for the current record. This is done in the control source of the txtBackground text box:

              =IIf(Nz([txtCurrentID],0)=Nz([ProductID],0),String(50,219),Null)

              Let’s break this down bit by bit. The expression uses the IIf function – the equivalent of If … Then … Else … in expressions.

              Nz([txtCurrentID],0)=Nz([ProductID],0) is the condition. The Nz function substitutes 0 (or whatever the second argument is) for nulls in the first argument. This condition basically compares txtCurrentID with ProductID, and returns True if they are equal (that is the case in the current record), False otherwise.

              String(50,219) is the value that is returned if the condition is True. This function returns 50 copies of the character with ANSI code 219. In standard fonts, character 219 is the letter

            • #655268

              That was a good explanation Hans. I will read over it numerous times until it soaks into my thick skull. I appreciate all your effort.

              Thank you!
              RonM

            • #655269

              It’s not your thick skull – I still get confused every time I try to understand it. Usually, I just copy a stock form I have and customize it. That way, I don’t have to bother with the details of highlighting the current record (or variants thereof) any more.

    Viewing 0 reply threads
    Reply To: Highlighting the active field/record (A97/SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: