alternating row colors in ListBox

eugzl

Member
Local time
Today, 08:56
Joined
Oct 26, 2021
Messages
127
Hi All.
Is it possible to create alternate row colors in a form ListBox control in VBA Access? If yes. Can someone show how it to do?
Is it possible to change font in header ListBox?
Thanks
 
Last edited:
usu the listbox is for picking 1 item. which gets highlighted.
one can also set it to pick many items which also get highlighted.
why would you mess it up by throwing in MORE colors to distract from the selected one?
 
You can build a subform that functions as a listbox and then format it any way you like. Format fonts and colors.
A listview control can do this, but those are hard to program.
 

Attachments

usu the listbox is for picking 1 item. which gets highlighted.
one can also set it to pick many items which also get highlighted.
why would you mess it up by throwing in MORE colors to distract from the selected one?
Hi Ranman256. Thanks for reply.
I don't have purpose to make busy view of ListBox. But if possible to create alternate color (light grey, white) and keep highlight row like black I don't think that will look like mess. But contrast of of alternate row color will help to view records in a ListBox.
Thanks
 
In my example I bolded the headers and set the list selector to yellow. Left is listbox right is simulated listbox using subform.
lb.jpg
 

Attachments

  • lb.jpg
    lb.jpg
    41 KB · Views: 616
You can build a subform that functions as a listbox and then format it any way you like. Format fonts and colors.
A listview control can do this, but those are hard to program.
Hi MajP. Thanks for reply.
That is interesting decision. But in that case would be better to change font color when row is selected.
AsListBox.png

Can you modify and resend attached file?
Thanks
 
Maybe this will help...
 
Last edited:
You can use conditional formatting to do whatever you want.
conditional.jpg
 
Last edited:
It may require a little bit of code as I have demonstrated, but bottom line there is nothing IMO you can do with a listbox you cannot do with a subform.
 
this example may be of interest
 
Hello.
what I know says that in the standard ListBox`s, you can't color the lines.
perhaps I can adapt the Lebans example;
 
perhaps I can adapt the Lebans example
I doubt you have the skill set to modify Leban's code. How versed are you in complex windows API? We already provided a working solution to show how to modify a standarard subform to work like a listbox. Provides everything asked for and more.
 
always say that I have difficulties in writing with the English language.
I agree that I am not able to modify the suggested.
I just tried to say that maybe someone with enough knowledge could get the desired path.
anyway...

I'll just keep watching.
thanks
 
It may require a little bit of code as I have demonstrated, but bottom line there is nothing IMO you can do with a listbox you cannot do with a subform.
Hi MajP.
I figured out how to modify highlighted color and font for selected record in continuous form. Can you show how to create double click event anywhere on a record of the continuous form to open another form?
Thanks.
 
Last edited:
See my discussion on Events and how you can make a single function that reacts to any double click event.
 
See my discussion on Events and how you can make a single function that reacts to any double click event.
Thanks for link. I found many helpful information since I'm new in Access.
I created code for double click event for continuous form to open child form. But unfortunately it doesn't work:
Code:
Private Sub txtHighLight_DblClick(Cancel As Integer)
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "fRequest"

        stLinkCriteria = "RequestID= " & CurrentID
        DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria, , , FormArg
End Sub
Where txtHighLight is text box that I'm using to highlight record when it selected. And CurrentID is unbound field that get value of PK when record selected.

But when I substitute the code by
Code:
Private Sub Form_DblClick(Cancel As Integer)
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "fRequest"

        stLinkCriteria = "RequestID= " & CurrentID
        DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria, , , FormArg
End Sub
and double click Record Selectors in that case even is working and child form is pop-up.

Could you show what need to do to double click anywhere on selected record on continuous form to open child form?
Thanks
 
Last edited:
I made a function
Code:
Public Function OpenForm()
  'in a controls double click event add =OpenForm
  DoCmd.OpenForm "Employees", , , "EmployeeID = " & Me.EmployeeID
End Function
Then in any control I can add in the doubleclick event
=OpenForm()
 

Attachments

I made a function
Code:
Public Function OpenForm()
  'in a controls double click event add =OpenForm
  DoCmd.OpenForm "Employees", , , "EmployeeID = " & Me.EmployeeID
End Function
Then in any control I can add in the doubleclick event
=OpenForm()
Thanks a lot. Works exactly like I expected. Now I will looking for how create search function for that.
Thanks.
 
I made a function
Code:
Public Function OpenForm()
  'in a controls double click event add =OpenForm
  DoCmd.OpenForm "Employees", , , "EmployeeID = " & Me.EmployeeID
End Function
Then in any control I can add in the doubleclick event
=OpenForm()
Hi MajP.
I tried to modify your double click function of continuous form in parent form that call child form. In that changes would like to open child form with title based on values of continuous form. In order to the title of the form shows the value that will be updated. That is code of function that I modified:
Code:
Public Function OpenForm()
    'those 2 line I added to create title for child form
    Dim formArg As Variant
    formArg = Me.SupplyID + "," + Me.Supply

    'in a controls double click event add =OpenForm
    DoCmd.OpenForm "fSupply", , , "SupplyID = " & Me.SupplyID, , , formArg
End Function
But when double clicked the record I'm getting error message:
DblClk_ContnsFormErr.png

after line formArg = Me.SupplyID + "," + Me.Supply
The code of Form_Open() In the child form looks like
Code:
Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)
    Dim formArg() As Variant
    formArg = Split(Form.OpenArgs, ",")
    Me.Caption = formArg(1)
End Sub
What is wrong? How to fix the problem?
Thanks
 
Last edited:

Users who are viewing this thread

Back
Top Bottom