Multiselect Listbox

G

gatarossi

Dear all,

In my form there is a multiselect listbox. Inside this listbox there
are some dates, for example: 01/01/07, 01/02/07, 01/03/07, 01/04/07...

I made a code that consist: each time that I select one date in my
multiselect listbox, in my subform appear one textbox. The problem is:

In my subform there are only 12 textbox and in the multiselect listbox
can exist more than 12 dates, and the code below in not flexible,
because I only can use the first twelve dates from the sequence of
dates in the multiselect listbox; and I would like that it pick the
first 12 dates that the user selected.

For example:

Multiselect Listbox - Dates
01/01/07
01/02/07
..
..
..

In the code below, if I click in 01/01/07 it will appear the textbox1,
if I click in 01/02/07 it will appear the textbox2.

But If I only click in 01/02/07, I would like that appear the
textbox1, not the textbox2.

This is the code:

Private Sub lstdata_Click()

If lstdata.Selected(0) = True Then
Me!despesas_subform!txtp1.ColumnHidden = False
Else
Me!despesas_subform!txtp1.ColumnHidden = True
End If

If lstdata.Selected(1) = True Then
Me!despesas_subform!txtp2.ColumnHidden = False
Else
Me!despesas_subform!txtp2.ColumnHidden = True
End If

If lstdata.Selected(2) = True Then
Me!despesas_subform!txtp3.ColumnHidden = False
Else
Me!despesas_subform!txtp3.ColumnHidden = True
End If

..
..
..

End Sub


Thanks!

André.
 
A

Arvin Meyer [MVP]

If what you are trying to do is build a string for an IN clause, you can do
it in a single textbox, instead of 12:

Dim varItem As Variant
Dim strList As String

With Me.lstElevation
If .MultiSelect = 0 Then
Me.txtSelected = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ","
Next varItem
If strList <> "" Then
strList = Left$(strList, Len(strList) - 1)
End If
Me.txtSelected = strList
End If

End With

lstElevation is a multi-select listbox, and txtSelected is a single textbox.
The code is run on the Click event of the listbox. The code above allows
unlimited number of selections from the listbox.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Dear all,

In my form there is a multiselect listbox. Inside this listbox there
are some dates, for example: 01/01/07, 01/02/07, 01/03/07, 01/04/07...

I made a code that consist: each time that I select one date in my
multiselect listbox, in my subform appear one textbox. The problem is:

In my subform there are only 12 textbox and in the multiselect listbox
can exist more than 12 dates, and the code below in not flexible,
because I only can use the first twelve dates from the sequence of
dates in the multiselect listbox; and I would like that it pick the
first 12 dates that the user selected.

For example:

Multiselect Listbox - Dates
01/01/07
01/02/07
..
..
..

In the code below, if I click in 01/01/07 it will appear the textbox1,
if I click in 01/02/07 it will appear the textbox2.

But If I only click in 01/02/07, I would like that appear the
textbox1, not the textbox2.

This is the code:

Private Sub lstdata_Click()

If lstdata.Selected(0) = True Then
Me!despesas_subform!txtp1.ColumnHidden = False
Else
Me!despesas_subform!txtp1.ColumnHidden = True
End If

If lstdata.Selected(1) = True Then
Me!despesas_subform!txtp2.ColumnHidden = False
Else
Me!despesas_subform!txtp2.ColumnHidden = True
End If

If lstdata.Selected(2) = True Then
Me!despesas_subform!txtp3.ColumnHidden = False
Else
Me!despesas_subform!txtp3.ColumnHidden = True
End If

..
..
..

End Sub


Thanks!

André.
 
G

gatarossi

Dear Arvin

I'm trying to build a form for expenses forecast. Then I have a form
and a subform coupled. It is like that:

Form
profit_center: (combobox with all profits center)
date: (listbox with all dates)

Subform
textbox textbox1 textobox2 textbox3
textbox4 textbox5 ...
expenses_code date1 date2
date3 date4 date5 ...

When the user opens de form all columns in my subform related with the
listbox date will be occult. Then when the user select one date, one
column will appear (these columns can't be related with the date, like
I show in my code - it's the problem!).

Thanks,

André.
 
A

Arvin Meyer [MVP]

Perhaps with an ActiveX grid control, but you cannot do that with the list
box.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Dear Arvin

I'm trying to build a form for expenses forecast. Then I have a form
and a subform coupled. It is like that:

Form
profit_center: (combobox with all profits center)
date: (listbox with all dates)

Subform
textbox textbox1 textobox2 textbox3
textbox4 textbox5 ...
expenses_code date1 date2
date3 date4 date5 ...

When the user opens de form all columns in my subform related with the
listbox date will be occult. Then when the user select one date, one
column will appear (these columns can't be related with the date, like
I show in my code - it's the problem!).

Thanks,

André.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top