alternating row colors in ListBox (1 Viewer)

eugzl

Member
Local time
Today, 09:02
Joined
Oct 26, 2021
Messages
125
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:

Ranman256

Well-known member
Local time
Today, 09:02
Joined
Apr 9, 2015
Messages
4,339
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?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:02
Joined
May 21, 2018
Messages
8,463
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

  • FrmAsListbox.accdb
    528 KB · Views: 486

eugzl

Member
Local time
Today, 09:02
Joined
Oct 26, 2021
Messages
125
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
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:02
Joined
May 21, 2018
Messages
8,463
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: 422

eugzl

Member
Local time
Today, 09:02
Joined
Oct 26, 2021
Messages
125
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
 

GinaWhipp

AWF VIP
Local time
Today, 09:02
Joined
Jun 21, 2011
Messages
5,901
Maybe this will help...
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:02
Joined
May 21, 2018
Messages
8,463
You can use conditional formatting to do whatever you want.
conditional.jpg
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:02
Joined
May 21, 2018
Messages
8,463
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.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:02
Joined
Feb 19, 2013
Messages
16,553
this example may be of interest
 

Mylton

Member
Local time
Today, 06:02
Joined
Aug 3, 2019
Messages
118
Hello.
what I know says that in the standard ListBox`s, you can't color the lines.
perhaps I can adapt the Lebans example;
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:02
Joined
May 21, 2018
Messages
8,463
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.
 

Mylton

Member
Local time
Today, 06:02
Joined
Aug 3, 2019
Messages
118
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
 

eugzl

Member
Local time
Today, 09:02
Joined
Oct 26, 2021
Messages
125
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:

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:02
Joined
May 21, 2018
Messages
8,463
See my discussion on Events and how you can make a single function that reacts to any double click event.
 

eugzl

Member
Local time
Today, 09:02
Joined
Oct 26, 2021
Messages
125
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:

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:02
Joined
May 21, 2018
Messages
8,463
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

  • FrmAsListbox.accdb
    904 KB · Views: 426

eugzl

Member
Local time
Today, 09:02
Joined
Oct 26, 2021
Messages
125
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.
 

eugzl

Member
Local time
Today, 09:02
Joined
Oct 26, 2021
Messages
125
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

Top Bottom