Select Listbox item from VBA (1 Viewer)

SteveClarkson

Registered User.
Local time
Today, 22:36
Joined
Feb 1, 2003
Messages
439
Hello all,

I have looked, but don't really know what I am searching for - so have given up and am asking you!

I have a listbox which lists people's names. This list can be filtered using a text box next door. Often, when you use the text box to filter (for example, you enter "smi" to find all the "Smith"'s) there is only 1 entry in the list box (not many people in the list you see)

Upon select the person's name in the list box, a subform updates with the persons' details.

I would like to be able to automatically display the persons details in the subform if there is only 1 person found in the search.

I have tried a couple of things, but am missing how to get VBA to select a particular (e.g. the first and only) list item.


Thank you very much indeed!
 

MarkK

bit cruncher
Local time
Today, 14:36
Joined
Mar 17, 2004
Messages
8,186
You can use the ListCount and ItemData properties of the list box control.
ListCount is obvious. ItemData is an array of bound column values that the control contains. Read more about these in Access help.
This code checks that there is at least one item in the list, and if so sets the value of the list to the value of the first item in the list. This selects the item.
Code:
If Me.MyList.ListCount > 0 Then Me.MyList = Me.MyList.ItemData(0)
 

SteveClarkson

Registered User.
Local time
Today, 22:36
Joined
Feb 1, 2003
Messages
439
Thank you very much - that worked a treat.

It is for a call-logging system - so every click I can shave off will be very time saving!
 

Users who are viewing this thread

Top Bottom