By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,475 Members | 2,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,475 IT Pros & Developers. It's quick & easy.

Getting the results from a list box

P: n/a
I've got a list box that has two columns. I would like to get the
value of the first column of the user selected row. How would I do
that? It is not a multiselect listbox.
PS Whats the difference between a "field list" and a "value list" in a
combobox?

Thanks in advance

Apr 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Karen Hill wrote:
I've got a list box that has two columns. I would like to get the
value of the first column of the user selected row. How would I do
that? It is not a multiselect listbox.


Me!ListBoxName.Column(0)

The columns are zero-based, so column 1 is index 0.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
Apr 20 '06 #2

P: n/a
Hi,

Thanks for the reply. It gets me the first column, but does it get me
the first column of the _user's_ selected row?

Apr 20 '06 #3

P: n/a
Karen Hill wrote:
Hi,

Thanks for the reply. It gets me the first column, but does it get me
the first column of the _user's_ selected row?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If the ListBox is NOT multiselect then there can only be one item
selected. Which means that

Me!ListBoxName.Column(0)

refers to the item selected by the user.

Put the line in the ListBox's AfterUpdate event routine:

Private Sub ListBoxName_AfterUpdate()

MsgBox "Item selected: " & Me!ListBoxName.Column(0)

End Sub

If you're using a multi-select ListBox you'll have to designated which
item in the ItemsSelected collection you want:

dim varItm as Variant
set ctl = Me!ListBoxName
with ctl
For Each varItm In .ItemsSelected
Debug.Print .Column(0, varItm)
Next varItm
end with

This routine prints the value of the 1st column in the ListBox, for all
selected items of a multi-select ListBox.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBREft/IechKqOuFEgEQI5ygCfRtVLVuiIvez73yv24w1GjKkrYaMAoOM N
k3vGTl7MGz1PV16jJynunReD
=TBp2
-----END PGP SIGNATURE-----
Apr 20 '06 #4

P: n/a
Say your listbox has the following... (2 columns)
ItemIDNo ItemText
1 Apple
2 Orange
3 Banana

If you want to return the *text*, (instead of the ItemIDNo), you need
to use

Me!ListBoxName.Column(1)

ItemIDNo is column number zero.
ItemText is column number one.

Hope that clarifies things.

Pieter

Apr 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.