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

Select input from list

Status
Not open for further replies.

alib9

Programmer
Nov 12, 2001
5
US
This is quite difficult to explain.

What I want to do is to get a user to select an input from a dropdown list.

I want it to look like the MsgBox prompt, but instead of having a single line for the input, I want to be able to let the user select the input from a list.

If this makes sense to anyone and they know how to help then I would be most appreciative. That is if it is possible!?

Thanks in advance.
 
Hi alib9,

Yes it is possible. You need to insert a UserForm. On the userForm, add a ListBox (use control toolbox). To find out how to link it with your source and output the date, you should look for the documentation on ListBoxes and controls and so on.

Nath
 
I haven't really used userforms/listboxes/comboboxes before.

Could you please help me in a bit more detail. I have tried looking for more information in help and the web, with no success.

I have an array of data. I want to use this data (like I said before(ish)) to prompt the user to select one of the items.

I think that to do this I need to transform the array into a listbox and then add this to a userform.

If anyone knows how to do this and could help me then this would be great.

I have defined a listbox and a userform but am then stumped as to what to do with them.

Thanks in advance.
 
Hi ALib9,

In a few words:

- Add Userform; in property window, set its name e.g fForm
- add ListBox; in property window, set its name e.g lbMyList
- if there are more then one column in your list, set its ColumnCount property to the right number of columns
- right click on the form and view code attached to it, select the event UserForm_Initialize()
- in this event, with code, define an array which contains the values you want to add, e.g myArray
- associate the array to the listbox: lbMyList.List()=myArray
- on the form add a button "OK".
- in the click event of the button, find out what the user has selected. The way I do it, I'm not sure is optimal, but it works:

Code:
For i = 0 to lbMyList.ListCount -1
    if lbMyList.Selected(i) then
        '... code about what to do with selected item
    end if 
Next i
[\code]

Hope this will be enough to put you on tracks.

Nath.
 
When I try and run the code an error is generated.

It says: "Method or datamember not found"

And the .list is highlighted.

I'm not sure what this means? I presume that I have misdefined something. But I can't see what?!

I have attached the code that I am using.

Sub selectsomething()

Dim listofthings As ListBox
Dim myform As UserForm
Dim things() As String

ReDim things(10)

For i = 0 To 10
mods(i) = i
Next i

listofmods.list() = mods

End Sub


 
There are some inconsistencies in variable names in your code (things becomes mods) but I suppose it is because you had to adapt it to explain the problem. I also suppose you do not declare the form and the listbox, but you actually use the names of the userforms and listbox you have inserted.

After these corrections, I couldn't replicate the problem.

I think the error message you receive means that it doesn't recognize listofmods as being a listbox object. Check spelling, check the name property of the listbox in the property window, try to attach the userform name before it: myform.listofmods.list()

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top