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

Referencing a listbox in an array

P: 18
I am trying to change a value in an array when the user selects a name a from a list or combo box. Also, I want the highlighted item to be displayed in a Label for the current selection. After all the names are selected from the boxes than I going to write those to a file or table. It sounds real simple and it probably is, but I am having a brain fart.

lblName - label
lstName - name of listbox
arrName (1, lstName) - array to hold item for list box

Thank you.
Sep 19 '07 #1
Share this Question
Share on Google+
7 Replies


P: 8
I would suggest uding a combo box with its style property set to "Simple Combo giving you a combo box with a listbox look and in the coding of the combo box on its click event use the following

Label1.Caption = combobox(index).text

Index Refering to the array number of the Combo box
Sep 19 '07 #2

kadghar
Expert 100+
P: 1,295
I am trying to change a value in an array when the user selects a name a from a list or combo box. Also, I want the highlighted item to be displayed in a Label for the current selection. After all the names are selected from the boxes than I going to write those to a file or table. It sounds real simple and it probably is, but I am having a brain fart.

lblName - label
lstName - name of listbox
arrName (1, lstName) - array to hold item for list box

Thank you.
Declare an integer (dim i as integer) and an array of strings (dim Arr1() as string) in the general declarations.

In the Change event of the listbox there should be something like this:

Expand|Select|Wrap|Line Numbers
  1. i=i+1 
  2. redim preserve arr1(1 to i)
  3. arr1(i) = listbox1.list(listbox1.listindex)
  4. label1.caption = listbox1.list(listbox1.listindex)
now you have all the selected items in the array
HTH
Sep 19 '07 #3

P: 18
lblCurrentPlayer.Caption = cmbPlayer(Index).Text

I still get an error. I have tried that syntax before, but I still don't think I am referencing the right part of the combo box. Does the cmbPlayer(Index).Text refer to the selected item from the combo box?
Sep 19 '07 #4

kadghar
Expert 100+
P: 1,295
lblCurrentPlayer.Caption = cmbPlayer(Index).Text

I still get an error. I have tried that syntax before, but I still don't think I am referencing the right part of the combo box. Does the cmbPlayer(Index).Text refer to the selected item from the combo box?
indexes are from 0 to the elements in the list box - 1

listbox1.listindex will return the hightlighted index, so if you use

lblcurrentplayer.caption = cmbplayer.list(cmbplayer.listindex)

will do
also works for combo boxes
Sep 19 '07 #5

P: 18
I've walked away from this, and I am trying this again. I still can only display the number from the combobox of the listindex.

Ex. Combo box has (mike, jim, alex, and pete). When I select Alex it is displayed by the listindex of 2. I want to show the name alex, and then store this in an array.


I cannot refereence cmbbox.list.(cmbbox.listindex) because my version of VBA doesn't have a .list property. Access 2000
Sep 21 '07 #6

kadghar
Expert 100+
P: 1,295
I've walked away from this, and I am trying this again. I still can only display the number from the combobox of the listindex.

Ex. Combo box has (mike, jim, alex, and pete). When I select Alex it is displayed by the listindex of 2. I want to show the name alex, and then store this in an array.


I cannot refereence cmbbox.list.(cmbbox.listindex) because my version of VBA doesn't have a .list property. Access 2000
I dont know why is this, i dont have access here to check it out, but in the while:

Since you're using a combobox, when you select something its showed as the combobox text. so you can store that by writing in the change procedure something like:

Expand|Select|Wrap|Line Numbers
  1. i=i+1
  2. redim preserve myArry(1 to i)
  3. myarr(i) = combobox1.text
  4. msgbox combobox1.text
Just make sure that the combobox matchrequired property is true.
HTH
Sep 21 '07 #7

P: 18
Thanks everyone for your input. I figured it out. I went to the control source feature in Access and put in this code to reference it to a text box. As soon as I had the value linked to the textbox everything else is easy.

=[cmbPlayer].[column](1)

I haven't done much programming the last 5 years, it is amazing how you forget little steps. Thanks again.
Sep 21 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.