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!

Need code to connect a combo box to a label. 2

Status
Not open for further replies.

lpressley

MIS
Dec 10, 2002
1
US
[pc3] I have a drop down combo box on a form, and when an item in the list is selected, the price for that item should show up in a label at the end of the row. Can anyone help me with the coding for this?

Your help would be appreciated!

[afro2]
 
Instead of a label, you could use a text box with
enabled=no
tab-stop=no
locked=yes
so that it looks like a label. Then set the control source to be:

comboboxname!column(2)

This returns the value in the second column of the Row Source of that combo for the selected item.

I'm assuming here that the price is the second field in the Row Source for the combo box. For example, if you're selecting from Table1, then the Row Source will be either:
a Table1 (and the price is the second field)
b a select statement: e.g. Select field1, price from table1
If it is not then change column(2) to column(3) or whatever is suitable.
 
Following what SarahG posted if you want to use a label you can use the following in the combo after update event, to set the caption property of the label.
Again adjust the number in the Column to the appropriate column (note that the column numbers start at 0)

Private Sub cboName_AfterUpdate()
lblName.Caption = cboName.Column(1)
End Sub

There are two ways to write error-free programs; only the third one works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top