Referring to a certain column of a listbox

  • Thread starter Thread starter bifteki via AccessMonster.com
  • Start date Start date
B

bifteki via AccessMonster.com

I want to refer to all the items of a specific column in a listbox one-by-one.
I tried to use the column property inside a for....next loop but I found out
it' s only used for the selected items in a listbox. If anyone could help me
I'd be thankful.
 
bifteki via AccessMonster.com said:
I want to refer to all the items of a specific column in a listbox one-by-one.
I tried to use the column property inside a for....next loop but I found out
it' s only used for the selected items in a listbox. If anyone could help me
I'd be thankful.


There is no reason why the column property can only be used for selected
items. Just refer to the column and row directly, and don't use the
ItemsSelected property.
 
To be more specific, I've written the following code to add e-mail addresses
to the 'To' property of the mailitem:

For lstId = 0 To Forms!frm_contacts.lst_contact_anipersons.ListCount - 1
contRecip = contRecip & "; " & Forms!frm_contacts!
lst_contact_anipersons.Column(2, lstId) & "@anima.gr"
Next lstId

obMessage.To = contRecip

Though I 'm not using any selectedtext property, when I display the obmessage,
the To part of the message is just a "@anima.gr" for every item in the list.
The VBA help for the column property says at some point:

"If the user has made no selection when you refer to a column in a
combo box or list box, the Column
property setting will be Null. You can use the IsNull function to
determine if a selection has been made..."

From what I get from this text, the Column property refers only to the
selected items.
Maybe I 'm wrong. If you have any ideas please reply.
 
Are you sure that the third column contains the contact info? If you are
getting multiple "@anima.gr" in the output, then it's iterating through the
rows of the list box.

Add this to debug:

Debug.Print Forms!frm_contacts.lst_contact_anipersons.ListCount
Debug.Print "0: " & Forms!frm_contacts.lst_contact_anipersons.Column(0,1)
Debug.Print "1: " & Forms!frm_contacts.lst_contact_anipersons.Column(1,1)
Debug.Print "2: " & Forms!frm_contacts.lst_contact_anipersons.Column(2,1)
Debug.Print "3: " & Forms!frm_contacts.lst_contact_anipersons.Column(3,1)

That might well tell you the whole story.
 
bifteki via AccessMonster.com said:
To be more specific, I've written the following code to add e-mail
addresses to the 'To' property of the mailitem:

For lstId = 0 To Forms!frm_contacts.lst_contact_anipersons.ListCount
- 1 contRecip = contRecip & "; " & Forms!frm_contacts!
lst_contact_anipersons.Column(2, lstId) & "@anima.gr"
Next lstId

obMessage.To = contRecip

Though I 'm not using any selectedtext property, when I display the
obmessage, the To part of the message is just a "@anima.gr" for every
item in the list. The VBA help for the column property says at some
point:

"If the user has made no selection when you refer to a
column in a combo box or list box, the Column
property setting will be Null. You can use the IsNull
function to determine if a selection has been made..."

From what I get from this text, the Column property refers only to the
selected items.
Maybe I 'm wrong. If you have any ideas please reply.

That caution only applies if you don't supply the row index. Are you
sure you are referring to the correct column? Column(2) is the third
column of the list box.
 
Randy said:
Are you sure that the third column contains the contact info? If you are
getting multiple "@anima.gr" in the output, then it's iterating through the
rows of the list box.

Add this to debug:

Debug.Print Forms!frm_contacts.lst_contact_anipersons.ListCount
Debug.Print "0: " & Forms!frm_contacts.lst_contact_anipersons.Column(0,1)
Debug.Print "1: " & Forms!frm_contacts.lst_contact_anipersons.Column(1,1)
Debug.Print "2: " & Forms!frm_contacts.lst_contact_anipersons.Column(2,1)
Debug.Print "3: " & Forms!frm_contacts.lst_contact_anipersons.Column(3,1)

That might well tell you the whole story.

Actually, I took Randy Harris's advice and it seems the 3rd column, the one I
wanted to refer to, is empty. I guess I 've made some mistake elsewhere in
the code. Anyway, thank you both for replying. Now I 'll just have to do some
correcting in my code.
 
Back
Top