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

Identifying the selected item in a form's listbox

Status
Not open for further replies.

MarkRobinson

Programmer
Feb 18, 2000
112
US
A form contains two listboxes displaying items from two tables (Table1 and Table2). The user has selected one item in each listbox.

A NEXT button adds a record to a Table3 with the id# of each item selected.

I'm looking for help with the code for the button. How do I identify the id# of the item selected?

Table 1
ID - Name
1 Item1
2 Item2
3 Item3

Table2
ID2 - Name2
1 2Item1
2 2Item2
3 2Item3

User selects Table1:Item2 and Table2:2Item3 and they are highlighted. Clicks Next

A new row in Table3 is added to read
2 3

I think the command I'm looking for to print the ID# is something like

Debug.Print Form.Table1.Selected.Id

... but not quite (or even close).

Also, is there an easy way I can select one from Table 1 and several from Table 2, building several new records in Table3?

Thanks!!
 
The selected item in a normal list box is the value of the listbox bound column. For a mutliselect listbox, you can iterate through ItemsSelected, there are a number of posts on the topic, but here is a note:

[tt] For Each itm In lstType.ItemsSelected
intSel = lstType.Column(0, itm)
'Update types.
UpdateTypes ID, intSel
Next[/tt]

Note the use of the Column property.
 
Thank you!
This:
"...value of the listbox bound column."
I don't understand.
Can you give me an example of how the statement might look?
I need to refer to
a) The id of the selected item in ListBox1 (Table1)
b) The ID of the selected item in Listbox2 (Table2)

Thanks for your help.

 
Got the first part

Box1SelectedItem = Form_FormName.ListBox1Name.Column(1)
Box2SelectedItem = Form_FormName.ListBox2Name.Column(1)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top