ListBox Issue

User avatar
Joseph
3StarLounger
Posts: 206
Joined: 31 Dec 2010, 22:23
Location: Columbia Falls, MT

ListBox Issue

Post by Joseph »

I'm trying to set the Rowsource for ListBox1, but everytime I do, I get an error. "Could not set the rowsource property. Invalid Property value."

I know the value is right, but why will it not work? Seems to work just fine on all my other forms....

Daily Data!BB2:BB100

User avatar
HansV
Administrator
Posts: 78542
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ListBox Issue

Post by HansV »

Try

'Daily Data'!BB2:BB100

Note the single quotes around the sheet name - they are required if the sheet name contains spaces.
Best wishes,
Hans

User avatar
Joseph
3StarLounger
Posts: 206
Joined: 31 Dec 2010, 22:23
Location: Columbia Falls, MT

Re: ListBox Issue

Post by Joseph »

Thanks again hans. That did it.

User avatar
Joseph
3StarLounger
Posts: 206
Joined: 31 Dec 2010, 22:23
Location: Columbia Falls, MT

Re: ListBox Issue

Post by Joseph »

Is it possible to select multiple values with in a listbox? If not, what type of object would allow?

User avatar
HansV
Administrator
Posts: 78542
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ListBox Issue

Post by HansV »

This is governed by the MultiSelect property of the list box. It has three possible values:

0 -fmMultiSelectSingle: the user can select only a single item.

1 -fmMultiSelectMulti: the user can select multiple items; clicking an unselected item selects it and clicking an already selected item deselects it.

2 -fmMultiSelectExtended: the user can select multiple items the same way you select files in Windows Explorer:
- Click on an item and Shift+click on another item to select both items and all items in between.
- Click and hold down the mouse to select a range of items by dragging over it.
- Ctrl+click to select and deselect individual items.

When you want to know which items the user selected in a multi-select list box, you can't use its Value or ListIndex property. Instead, use the Selected property; this is an array of True/False values:

Code: Select all

  Dim i As Long
  For i = 0 To Me.ListBox1.ListCount - 1
    If Me.ListBox1.Selected(i) Then
      ' i-th item is selected
      ...
    End If
  Next i
Note that the index is zero-based: the first item has index 0 etc.

If you want to deselect all items in a list box:

Code: Select all

  Dim i As Long
  For i = 0 To Me.ListBox1.ListCount - 1
    Me.ListBox1.Selected(i) = False
  Next i
etc.
Best wishes,
Hans

User avatar
Joseph
3StarLounger
Posts: 206
Joined: 31 Dec 2010, 22:23
Location: Columbia Falls, MT

Re: ListBox Issue

Post by Joseph »

Perfect. Thanks Hans!!!

User avatar
Joseph
3StarLounger
Posts: 206
Joined: 31 Dec 2010, 22:23
Location: Columbia Falls, MT

Re: ListBox Issue

Post by Joseph »

Just another question.

Suppose I want to add a "Notes" textbox. Is there a way to format the textbox to use more than one line?

Example:
Current:
Here is how the text is normally entered in to the text box, however I need it to do this.

Desired:
Here is how the
text is normally
entered in to the
text box, however
I need it to do this.

I want the text to drop down once the border of the textbox is reached.

User avatar
HansV
Administrator
Posts: 78542
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ListBox Issue

Post by HansV »

Set the following properties of the text box:

Multiline: True (this allows text to wrap automatically)
EnterKeyBehavior: True (this makes it possible to start a new line by pressing Enter in the text box)

and optionally:

ScrollBars: 2 -fmScrollBarsVertical (when the text is longer than will fit in the text box, a vertical scroll bar will appear)
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78542
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ListBox Issue

Post by HansV »

I have moved your question about importing sheets to a thread of its own: Import all sheets from another workbook since it is not related to the subject of this thread. I have posted a reply there.
Best wishes,
Hans