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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Choosing value in a list box.

Status
Not open for further replies.

obheron

Technical User
May 25, 2005
40
US
Hi all,
I have a list box with a single entry. How do I set the list box so that it chooses that value without having to click on the list box?

Thanks.
 
One way:
Me![ListBox name].Selected(0) = True
Another way:
Me![ListBox name].Value = Me![ListBox name].ItemData(0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Which event do I place this is? Before Update, After, etc...
 
How are ya ChasBoots . . . . .

Try the [blue]Onload[/blue] event as an initial guess.

If this data is static, [blue]why a listbox[/blue] (espcially since your preselecting the only value)?

Calvin.gif
See Ya! . . . . . .
 
It's value is chosen based on the users choice in a combo box. I could not find a way to set the value of a text box based on a choice in a combo box. So i used a list box so I could utilize the RowSource property.

Is there an easy way to set a text box to a value based on the combo box choice?

 
set a text box to a value based on the combo box choice
Me![textbox name] = Me![combo name].Column(n)

where n is the column number (option base 0) you want to grab.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Roger That obheron . . . . .
obheron said:
[blue]Is there an easy way to set a text box to a value based on the combo box choice?[/blue]
This is what you should've asked in your post origination!
Code:
[blue]   Me![YourTextboxName] = Me![YourComboboxName].Column(1)[/blue]
You may have to play with the column number to get it right.

Note:The column [blue]index starts at zero[/blue] and includes any columns hidden with the [blue]Column Widths[/blue] property.

Calvin.gif
See Ya! . . . . . .
 
Ok, I will try that, but the question is where do I put that line of code? Before Update, After Update, Default value etc.

The code is helpful but I also need the location to put it!

thanks!
 
In the AfterUpdate event procedure of the combo.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Think I should clarify. The combo box only has one column which I use as a query to determine the value of the text box. The text box does not equal the value of the combo box.

ex.

Fruit1_Fruit2 | Fruit1 | Fruit2 |
Fruit3_Fruit4 | Fruit3 | Fruit4 |

If my combo box has the option Fruit1_Fruit2 chosen, then one text box has the value Fruit1 and another has the value Fruit2.

HTH
 
Can you please post the value of the RowSource property of the combo ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
SELECT [Fruit Relationships].[Fruit Relationship] FROM [Fruit Relationships];

this is what is in the rowsource property, with name substitutions.

HTH, see you in the AM
 
which I use as a query to determine the value of the text box
Any chance you could post this SQL too ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That is the SQL code that is in the SQL view of the query.
Do you mean something else?
 
Hi, obheron,
obheron said:
The combo box only has one column which I use as a query to determine the value of the text box.
I presume this to mean that the selection in the combo becomes the criteria for a query, the result of which you wish to place in a textbox? In that case, yes, please post the SQL of the query.

Ken S.
 
I figured out what I was doing. Added the other columns to the combo box and hid them, then set the value of the text box equal to a value in one of the hidden columns.

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top