Results 1 to 10 of 10
  1. #1
    almontaser92 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2022
    Posts
    5

    Highlighting the current row in continuous forms programmatically

    A long time ago I found a function that highlights the current row in the continuous form and modified it to enhance its performance (from my opinion), I attached it to the isladogs example in this thread at this link.
    - One of the issues that was bothering me was the width of the text box that highlights the row, because it takes the same width as the form, it interferes with the rest of the controls and is difficult to work with while selecting or aligning them.
    - The other issue is changing the background color of the focused text box, when the focus moves to any text box, the background of the selected text box becomes the same color as the BackColor property.
    - The ability to customize the highlight color .
    Everything that is required is explained in the code but in short these are the steps
    1. Import the mdlHighlightRow module
    2. Create a text box in the details section (it does not matter how wide) and modify its properties as follows
    - Control Source = [the name of the field that contains the unique values]
    - Enabled = No


    - Locked = Yes
    - Background Style = Normal
    - Special Effect = Flat
    - Font Size = 1
    - Tag = "UniqueValue"
    - Send it to the back of other controls
    3. Assuming that the textbox set up in the settings above was named [txtUniqueValue] Add the following to the form's OnCurrent event
    - =HighlightRow([txtUniqueValue]) "OnCurrent event in the Properties sheet"
    Or
    - Call HighlightRow([txtUniqueValue]) " within the OnCurrent subprocedure "
    That's all, you can download the attached file, try it out and provide any feedback or errors.

    HighlightCurrentRecord.zip

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Should probably have posted this into the Access Knowledge Base section, possibly in Tutorials subforum. If you are able to move your own thread, suggest doing so. Or maybe a moderator will do it.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    in my opinion, this can be done without much code.
    and also the code you have always Delete/Recreate the CF on the current event
    of the form, which is not optimal. You only need to set the CF once.
    Attached Files Attached Files

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I've only just noticed this thread.

    By chance I recently created a variation on my original example: Highlight Current Record Using Transparency

    With minimal code, this allows me to create effects such as:
    Click image for larger version. 

Name:	HighlightCurrentRecordTransparency.png 
Views:	20 
Size:	37.4 KB 
ID:	53053

    You can also modify the appearance of the highlighted record e.g.

    Click image for larger version. 

Name:	HighlightCurrentRecordBox.png 
Views:	20 
Size:	39.1 KB 
ID:	53055

    You can also underline the current record using any of the available border styles:

    Click image for larger version. 

Name:	DashUnderlineRecord.png 
Views:	20 
Size:	39.7 KB 
ID:	53054

    Similar effects can be done for the current control: Highlight Current Control Using Transparency

    Click image for larger version. 

Name:	HighlightCurrentControl.png 
Views:	20 
Size:	36.8 KB 
ID:	53056
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2021
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Quote Originally Posted by jojowhite View Post
    in my opinion, this can be done without much code.
    and also the code you have always Delete/Recreate the CF on the current event
    of the form, which is not optimal. You only need to set the CF once.
    jojo, I had high hopes for using this technique - until I tried to edit a field, changing Alexandre to Alexander.

    Click image for larger version. 

Name:	HI-jojo.png 
Views:	18 
Size:	39.2 KB 
ID:	53057

  6. #6
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    sorry about that, I just copied the Contacts table from the New Northwind.
    and upon Modifying the table, I found that it as a Before Change data macro.
    deleting the macro, will remove the message.

  7. #7
    almontaser92 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2022
    Posts
    5
    Quote Originally Posted by jojowhite View Post
    in my opinion, this can be done without much code.
    and also the code you have always Delete/Recreate the CF on the current event
    of the form, which is not optimal. You only need to set the CF once.
    I agree that the method you suggest is easier, but it has two issues
    1- The BackStyle Property of all controls should be Normal, so if for any reason you have to make it Transparent, then the Highlighting will only be shown for the text box that the focus is on.
    2- This issue may not be important, but it requires caution from the developer, when adding a new text box, the conditional formatting must be copied to it, otherwise it will remain unaffected, and if a text box is copied from this form to another form, it will require deleting the CF, otherwise an error message will appear.

    Quote Originally Posted by isladogs View Post
    I've only just noticed this thread.

    By chance I recently created a variation on my original example: Highlight Current Record Using Transparency

    With minimal code, this allows me to create effects such as:
    It's a great way to do it, but the issue I mentioned in my post remains.

    One issue that was bothering me was the width of the text box that highlights the row, because it takes the same width as the form, interferes with the rest of the controls and is difficult to work with while selecting or aligning
    So I minimized the width of BoxHighlight text box to the smallest possible width so that it is away from the first text box and added these lines to the FormLoad subroutine
    Me.BoxHighlight.Left = PupilID.Left = 0.1
    Me.BoxHighlight.Top = PupilID.Top - 0.1
    Me.BoxHighlight.Height = PupilID.Height + 0.2
    Me.BoxHighlight.Width = TutorGroup.Left + TutorGroup.Width + 0.1
    The idea worked, but it would be nice if the code could be more generalized so that I am not restricted by the names of the controls as (PupilID and TutorGroup)

  8. #8
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Sorry but I don't know what you mean by the highlighted control
    interferes with the rest of the controls and is difficult to work with while selecting or aligning
    In both examples, the individual fields can be selected and are editable. The controls can also be individually selected in design view. So what exactly is the issue for you?

    You are, of course, welcome to modify any of my example apps and indeed to apply/adapt the ideas in your own apps.

    Personally I don't have an issue with the width of the highlight controls in either example - in fact I deliberately made them (almost) fill the width of the detail section

    As for your 4 added lines of code (the first line should be - not =), there is no need to hardcode references to individual controls
    If you want to use that approach, then you could instead use something like:
    Code:
    Me.BoxHighlight.Left = 100    
    Me.BoxHighlight.Width = Me.InsideWidth - 400
    Me.BoxHighlight.Top = 50
    Me.BoxHighlight.Height = Me.Detail.Height - 100
    Again, modify this as you wish
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #9
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,935
    I am not restricted by the names of the controls as (PupilID and TutorGroup)
    use code to loop through the controls (in presumably the detail section) to find the name of the leftmost and rightmost controls

    Also the left, width, etc properties in vba are manipulated in twips not cm or inches. 0.1 cm would be 57 twips. But for more accuracy on the screen, set in pixels. so round to 60 (15 twips to a pixel)

  10. #10
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    i copied those textboxes (with cf) to the new form.
    yes the CF is copied, but I found no errors even when I edit the records using
    the new form.

    there was an error on frmHighlightRecords when the form's AllowAddtions is set to True.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Highlighting a current row in a form
    By WCStarks in forum Forms
    Replies: 7
    Last Post: 12-20-2020, 09:23 AM
  2. Capture event: highlighting record row within query or subform
    By BrainExplodingFromCoffee in forum Programming
    Replies: 4
    Last Post: 04-26-2016, 02:50 PM
  3. Replies: 2
    Last Post: 02-28-2013, 07:29 AM
  4. Highlighting current txtBox
    By SMC in forum Forms
    Replies: 1
    Last Post: 06-21-2012, 07:46 AM
  5. Change Row Background Color Programmatically
    By sales@4bco.com in forum Programming
    Replies: 2
    Last Post: 10-25-2009, 11:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums