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!

Defaulting to a value in a listbox

Status
Not open for further replies.

batteam

Programmer
Sep 12, 2003
374
US
I have a listbox Access Project - Access 2000) on a form that shows policy numbers and associated data. When it's populated from a stored procedure (SQL 2000 table), it shows all the policy numbers (can be just one or up to four or five)owned by a person on the form. I (actually my boss) would like the list box to default to the row containing the policy number same as the contents of a textbox containing a policy number on the form.

Bottom line: anyway to make a selection in a listbox automatically, without actually clicking on a selection with the mouse? I have tried setting the default value to the text box contents but no luck. Also, just setting the listbox to the value, like: lstboxMyListBox = txtpolicyNo didn't work either.

Thanks for any assistance or hints in this.
 
Have you tried setting the Selected property of the listbox?
 
Can you change it to a combo box? Just setting the combo box equal to whatever it is you want will work. I think you have to set the List Index with a list box.
 
Thanks to both for responding. Becca999: I do need a list box for my application - or a subform as multiple selections will be made by users. I haven't worked iwth listbox indexes yet but will look into them as they might be valuable sometime in the future. cjowsey: I took another look at the 'Select' property and decided if this was to be done, that might be the area I should look into further. I did and, because I have a limited rows that will be displayed in my listbox, I was able to use a couple nested 'Select Case' statements to read out each column value then compare it to my textbox value and if a match, use the 'Select' method to select that row. Again, I was able to manage this because my listbox will only have a limited number of rows displayed in it (<10) at any one time. Thanks again to both for your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top