Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2020
    Posts
    15

    Conditional formatting IN combobox dropdown


    Good morning. I have a combobox on my form that I am working with. If a record has a bool field set to TRUE, I would like it to highlight that row in the combobox dropdown, while other rows in the combobox dropdown remain unaffected. Is this possible? Thank you very much.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    Quote Originally Posted by hightekkrednek View Post
    Good morning. I have a combo box on my form that I am working with. If a record has a bool field set to TRUE, I would like it to highlight that row in the combobox dropdown, while other rows in the combo-box drop-down remain unaffected. Is this possible? Thank you very much.
    I don't think that is possible
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,776
    I have seen similar requests and the proposed idea was to replicate the list as a subform, but it was just an untried suggestion. Such a subform would never behave as a drop down list without a lot of code that is probably way more effort than it's worth. It would be an interesting exercise though.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,776
    As a follow up: I've been playing with the notion for some time and here are a few basics of what I've found when attempting this with textbox bound to a single field, assuming you want to approximate a combo look:
    - you have to use a continuous form, otherwise the possibility of highlighting is zero, and you will not be able to eliminate headers if using a datasheet
    - the subform needs several properties set (no border, cf default view, sized tight to textbox on all sides, vertical scrollbar only, no nav buttons or selectors, etc.)
    - subform control must be tightly sized also
    - the command button to drop down must be on the main form, otherwise there is a button for each record
    - command button cannot overlay subform control, thus it can only get as close as the subform scrollbar (which is compressed into just buttons). Ended up turning scrollbar on and off with drop down/collapse and doesn't look too bad.
    - drop down/collapse done in steps of 325 and -325 to simulate a combo
    - drop down height is x times recordset count (325 for x is not bad for the font I used but not perfect)

    I stopped there because conditional formatting the row would be the next step but I don't think I'll take it. That would likely need a transparent textbox whose background color property is controlled by cf. Seems like it should be possible though.

    Click image for larger version. 

Name:	cfCombo1.jpg 
Views:	8 
Size:	3.4 KB 
ID:	42651
    Click image for larger version. 

Name:	cfCombo2.jpg 
Views:	7 
Size:	12.9 KB 
ID:	42652
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,776
    If anyone is interested, here's the code I just threw together for a test form upon which I didn't worry about proper controls names as I wasn't sure it would work at all. Note that I altered the size factor to 315 and it seems to look better.

    Code:
    Private Sub Command4_Click()
    Dim ctl As Control
    Dim frm As Form
    Dim l As Long
    
    Set frm = Me.Child0.Form
    Set ctl = Me.Child0
    
    If ctl.Height > 315 Then 'expanded now, so collapse it
        For l = 315 * frm.Recordset.RecordCount To 315 Step -315
            ctl.Height = l
            ctl.Form.ScrollBars = 0
            Me.Repaint
        Next
        Exit Sub
    End If
    
    If frm.Recordset.RecordCount > 0 Then
        For l = 315 To 320 * frm.Recordset.RecordCount Step 315
        ctl.Height = l
        Me.Repaint
        Next l
        ctl.Form.ScrollBars = 2
    Else
        ctl.Height = 315
    End If
    
    End Sub
    NOTE: obviously there would have to be a height limit based on the form. You wouldn't want to drop it down a thousand rows, for example. The fix then, would be to know the size factor (e.g. 315) and multiply that by a row factor that you pick (e.g. 10) and have the loop go from 315 to 315*10 (3150) for example. The scroll bars will allow access to the records that are below the bottom of the control. Alternately, you could code to use the record count if less than 11 but use the factors if it's 11 or more. That way, it would be dynamic up to a point, then fixed in height thereafter.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 27
    Last Post: 07-28-2016, 07:13 AM
  2. Conditional formatting for combobox
    By boboivan in forum Access
    Replies: 4
    Last Post: 04-24-2016, 05:07 AM
  3. Replies: 2
    Last Post: 11-12-2015, 10:46 AM
  4. Replies: 6
    Last Post: 05-26-2013, 09:10 PM
  5. Combobox Dropdown Problem
    By ssashraf in forum Access
    Replies: 3
    Last Post: 12-08-2012, 11:36 PM

Tags for this Thread

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