Solved Listbox (1 Viewer)

kavehrad

New member
Local time
Today, 18:05
Joined
Jun 14, 2020
Messages
17
Hi all
Can I have a list box in a form that looks like the attached image and I can search for records that begin with each letter?

Thanks
 

Attachments

  • Listbox.png
    Listbox.png
    6.8 KB · Views: 89

isladogs

MVP / VIP
Local time
Today, 17:05
Joined
Jan 14, 2017
Messages
18,227
I don't think so.
However you could have 26 text boxes above your listbox with code to filter the list by first letter.
Or use a tab control with 26 tab pages
Or use cascading combo boxes
 

June7

AWF VIP
Local time
Today, 08:05
Joined
Mar 9, 2014
Messages
5,473
Use textboxes or buttons.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:05
Joined
Sep 21, 2011
Messages
14,306
Hi all
Can I have a list box in a form that looks like the attached image and I can search for records that begin with each letter?

Thanks
Why no V ?
 

June7

AWF VIP
Local time
Today, 08:05
Joined
Mar 9, 2014
Messages
5,473
Set listbox RowSource property. Code in each button Click event:

Me.Listboxname.RowSource = "SELECT * FROM table WHERE somefield LIKE 'A*';"
 

kavehrad

New member
Local time
Today, 18:05
Joined
Jun 14, 2020
Messages
17
Set listbox RowSource property. Code in each button Click event:

Me.Listboxname.RowSource = "SELECT * FROM table WHERE somefield LIKE 'A*';"
I have tried to do that but it doesn´t work. I attach my DB here. Maybe I did something wrong
 

Attachments

  • Tunet.accdb
    2.6 MB · Views: 59

moke123

AWF VIP
Local time
Today, 12:05
Joined
Jan 11, 2013
Messages
3,920
Heres an example. I only did up to letter f but it should give you the idea.
Note that I changed your table name and listbox name. I wouldnt use special characters in names and wouldn't name a listbox the same as a field.
 

Attachments

  • Tunet (1).accdb
    2.6 MB · Views: 59

moke123

AWF VIP
Local time
Today, 12:05
Joined
Jan 11, 2013
Messages
3,920
It just occurred to me after posting an easier way to code this.

There is a function as so
Code:
Private Function SetRowSource()

Me.lbxNamn.RowSource = "SELECT * FROM tblKund WHERE Namn LIKE """ & Screen.ActiveControl.Tag & "*"""

End Function
each button has a letter in its Tag property.

if you select all the buttons at once and type in the onlick event
=SetRowSource()
the code will run when you click the button

see this example
 

Attachments

  • ExampleTunet .accdb
    2.6 MB · Views: 74

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:05
Joined
Jul 9, 2003
Messages
16,282
can search for records that begin with each letter?

Your question reminded me of a Form I know about from an early version of the Microsoft Northwind Sample database. The Northwind database is a database provided by Microsoft to demonstrate the functionality available in Microsoft Access. It's for demonstration purposes only, and you shouldn't use it for doing accounts, not unless you change some things as described on my website here:- Northwind Problem and Solution

In the YouTube Video I show the Form, and I point out a feature that I think might be useful to you and that is an Option Group, but not a normal Option Group, it's an option group containing letters (Toggle Buttons). A very clever idea. as many of the features demonstrated in the Northwind Sample database are. They are well worth exploring to see what you can do with Microsoft Access and I recommend everyone should download your own copy to peruse.

Northwind Customer Phone List - Nifty Access


I also provide a list of download links to the various Microsoft Northwind Sample files HERE:- https://www.niftyaccess.com/northwind-downloads/

The Northwind links page is getting a bit dated, I'm not 100% sure if all the links work! Feedback would be useful!

If you find my video useful then I would be grateful if you would sign up to my YouTube channel. I'm hoping to get to 1000 followers shortly, which opens up a tranche of upgrades which I'm really looking forward to having!

Uncle Gizmo's YouTube channel

Bare Link:-

If you sign up you will get notified every time I upload a new video demonstrating a solution to a problem in MS Access...
 
Last edited:

cheekybuddha

AWF VIP
Local time
Today, 17:05
Joined
Jul 21, 2014
Messages
2,280
@Tera

Just create a label containing the alphabet and use a fixed width font. (Name it 'lblAlpha')

Then use the code in the link:
Code:
Private Sub lblAlpha_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As  Single)
  Me.Filter = "fldLastName LIKE '" & Chr(64 - Int(-X / Me.lblAlpha.Width * 26)) & "*'"
  Me.FilterOn = True
End Sub
 
Last edited:

moke123

AWF VIP
Local time
Today, 12:05
Joined
Jan 11, 2013
Messages
3,920
I just tried it. I never would have thought of it. Its a keeper for someday.
 

deletedT

Guest
Local time
Today, 17:05
Joined
Feb 2, 2019
Messages
1,218
@kavehrad

See if this does what you want.
If you start clicking from A, your sample file works until letter H
The letter I doesn't filter the listbox.
From J it filters the previous letter. J filters I, K shows J etc.

Once this happens, nothing filters correctly anymore.

This is what I receive after clicking Y.

2020-06-15_10-07-57.jpg
 
Last edited:

cheekybuddha

AWF VIP
Local time
Today, 17:05
Joined
Jul 21, 2014
Messages
2,280
What font are you using? It must be a Fixed-Width font.

Make sure the label width doesn't have any space after the 'Z'
 

deletedT

Guest
Local time
Today, 17:05
Joined
Feb 2, 2019
Messages
1,218
What font are you using? It must be a Fixed-Width font.

Make sure the label width doesn't have any space after the 'Z'
I didn't use any font. I simply opened your form in sample file attached in #17

Edit : to be sure, I opened the form in design view and changed the font to Courier New. Still the same.
 

Users who are viewing this thread

Top Bottom