Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Select the first record in a listbox

Status
Not open for further replies.

Ktx7ca

IS-IT--Management
Apr 5, 2008
88
CA
Hello

I need to get a list box to automaticlly select the first record when it's populated.

any ideas on how to do that would be great aprecatited

Thanks Chris
 
Me.Lstbox = Me.Lstbox.Column(me.listbox.boundcolumn, 1+iif(me.listbox.columnheds=-1,1,0))
 
Or if you just used the wizard to create your listbox, on the Default property of the listbox put:
=[List0].[ItemData](0)

where List0 is the name of your listbox.
 
HI pwise

Thanks for the info, I still have a bit of a problem, I get the gray doted line around the first record, Instead of the black highlited line I was looking for. and of course the listbox selection value is empty.

any thoughts

thanks chris
 
HI fniely

I'm having the same issue I had with pwise's advice. maybe I asked the wrong question as what I'm getting is that it's highlighted but not selected in my way of discribing it (or clicked if you will)

Thanks Chris

 
No luck there Maybe I have it in the wrong event
 
it's highlighted but not selected in my way of discribing it (or clicked if you will)"

First, my highlights the first entry in the listbox.
Second, If you always want the first item "clicked", then how does the user click any of the other items? I'm assuming that On Click you're having something happen. I was going to ask if you had a multi-select listbox but that wouldn't make any sense, either. That would mean the user always wants the first item.

Maybe you could explain further.
 
Sure no problem

90% of the time the list box will only return 1 entry. and I need it to be automaticaly selected and activate the onclick event

8% of the time of the time serveral enteries will be returned but the first entry will be the correct entry. So I still want it to autoselect the first entry

For the last 2% of the time that the first entry is not what they want they will they will select the correct one from the other entries returned them selves.

does that make any sence I hope so

from working with this is I have found that after the provided code has run if I press the down arrow I get the desired result. if that helps any toward a solution

thanks chris
 
G'day Chris,

If I get you right then this should sort your drama:

Code:
me.listbox.selected(0)=true

Have a great weekend

JB
 
You need to set the focus first before selecting the first item.


Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
How are ya Ktx7ca . . .

There's quite a bit of ambiguous/unclear operations going on here. [surprise]

You say:
Ktx7ca said:
[blue]8% of the time of the time serveral enteries will be returned [purple]but the first entry will be the correct entry.[/purple][/blue]
Are you saying all entries are discarded save the first? [neutral] This is also indicitive of a [blue]multiselect listbox[/blue], meaning what you use to run your code is outside of the listbox events!

Then you say:
Ktx7ca said:
[blue]For the last 2% of the time that [purple]the first entry is not what they want[/purple] they will they will select the correct one from the other entries returned them selves.[/blue]
From the two quotes above [blue]there's no way to know if the first entry is required or not![/blue] I hope you can see this.

The esaiest way out here is to let the users select what they know they need and be done with it!
TheAceMan1 said:
[blue]If users don't know what they should select then they'll just have to learn (perhaps a quick class).[/blue]

[blue]Your Thoughts . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
HI Sorry for the delay in getting back to you. JBinQLD your Idea works great thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top