Multiselect Listbox

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) =3D True Then
    Me!despesas_subform!txtp1.ColumnHidden =3D False
Else
    Me!despesas_subform!txtp1.ColumnHidden =3D True
End If

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

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

..
..
..

End Sub


Thanks!

Andr=E9.

0
gatarossi
7/12/2007 10:22:19 AM
access 16762 articles. 3 followers. Follow

3 Replies
939 Views

Similar Articles

[PageSpeed] 44

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

<gatarossi@ig.com.br> wrote in message 
news:1184235739.031538.64740@k79g2000hse.googlegroups.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�.


0
Arvin
7/12/2007 12:55:04 PM
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=E9.

0
gatarossi
7/12/2007 1:32:04 PM
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

<gatarossi@ig.com.br> wrote in message 
news:1184247124.421895.209600@q75g2000hsh.googlegroups.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�.


0
Arvin
7/14/2007 4:02:02 PM
Reply:

Similar Artilces:

Use listboxs to select multiple answers for table
Morning All I'm currently using MSAccess 2000, and need to use a list box so users can choose/ click on multiple answers (up to 5) that are then saved to the underlying records in the table when the user clicks on the save button. I have tried various ways to do this but all to no avail. Would really appreciate some help/ guidance with this issue. My form's name is frmInquiry, the underlying table that needs saving into is named tblInquiryCalls and the individual records names within this table are called Issue1 through to Issue5. The unbound list box on the form is called lstAv...

ListBox
Hi, I have a ListBox in a dialog. There are more places (functions) from which strings can be added to that listbox. I am wondering where is the best place to put the method call SetHorizontalExtent, as the width of strings is know just at run time. I don't want to call that function from every place, from which a string is added to the listbox. I would prefer to place that function in some WM_MESSAGE handler, which would be called by a framework at every time, the string is added to the listbox. I didn't find such appropriate message. Can anybody tell me which message is t...

Control using a Listbox
Hey, I have a form of records, and a listbox with all of the dates from said records. Anyone know a way to select one of the dates in the listbox and click a button to edit that record. I've tried findrecord and openform with that date as a filter but I always just get the first record shown. Also I have a report and was wondering if you knew how to make the selected record in the same listbox the last record displayed in the report, sort of like printing the week ending. Thanks The wizard doesn't build the criteria. You need to build it. Open the code module and provide a val...

Storing values from listbox
I have a listbox (lst_Cables) which holds date and quantity of all the entries made. I also have a textbox (txt_Start) this textbox displays the date of the last entry in the lst_Cables. When the listbox is cleared the date value in txt_Start remains however when the form is closed and then re-opend the value in txt_Start is gone and an error message appears instead. I'm assuming this occurs because the listbox is empty and the default value of the textbox resets itself. What I want to do is somehow to store the date value displayed in the textbox (txt_start) so that when I re-open the fo...

ListBox TextAlign-Property Question
Hi, I'm using a ListBox with 5 Columns in a form. Is it possible to align the value for every column differently? Eg. Column1 left, Column 2 right, Column 3 left ... Regards, Rainer ...

Excel Macro Listbox?
Hi, I'm trying to get an Excel macro to display the contents of a folder and allow me to select and open a single file from the folder. I can get it to store the filenames in an array but everything I've tried to get a listbox to work has resulted in incomprehensible error messages. Anyone know how to do this? Code examples? TIA -- John Thow an optimist is a guy/ that has never had/ much experience - certain maxims of archie; Don Marquis. To e-mail me, replace the DOTs in the Reply-To: address with dots! Hi John Usually the built-in GetOpenFIlename method is far better for ...

copying the contents of a drop down list from the listbox itself?
Is there a way to copy just the contents of the drop down list (from a filter for example). From the listbox itself? Thx, D ...

Listbox Highlight selection
I have a listbox that I want to select the last row in the box and scroll to that row. Can I do this? I used this statement lbx_results.Selected(lbx_results.ListCount - 1) = True Maybe something like: With lbx_results .TopIndex = .ListCount - 1 .Selected(lbx_results.ListCount - 1) = True End With cd wrote: > > I have a listbox that I want to select the last row in the box and > scroll to that row. > Can I do this? > > I used this statement > lbx_results.Selected(lbx_results.ListCount - 1) = True -- Dave Peterson ...

MultiSelection, Undo and more
Hi, I wanna write a GUI editor. Object may be: Frames, Buttons, Labels, Combo Boxes, Images etc. I need to implement, multiple selection and Undo command. I need some help on designing, also as many as sample project exists. Thanks, Janiv Ratson. Janiv, Haven't I answered this? Progressive Alzheimer :-) You'll find all of that in: http://www.codeproject.com/miscctrl/diagrameditor.asp which is a free source code project that you might either steal, derive from or use as a warning example. The project has both multiple selection and (unlimited) undo, as well as much, much more, f...

MeasureItem, DrawText and multiline listbox problem
I have a multiline listbox where even though there is plenty of room for the item text to display as a single line, it displays as two lines in the listbox. I set the item height in the overridden MeasureItem function: void PColorListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { ASSERT(lpMeasureItemStruct->CtlType == ODT_LISTBOX); //LPCTSTR lpszText = (LPCTSTR) lpMeasureItemStruct->itemData; //ASSERT(lpszText != NULL); CSize sz; CDC* pDC = GetDC(); int item = lpMeasureItemStruct->itemID; CString text(""); GetText(item, text); CRect rect;...

ListBox Operation Putting Form Into Some Kind Of State?
When this code runs: --------------------------------- 3030 With Me.lstIssuers 3031 If .ListCount > 0 Then 3032 .SetFocus 3033 .ListIndex = 0 'Force selection of first row 3034 End If 3035 End With 3036 Me.cmdClose.SetFocus --------------------------------- It traps out on line# 3036. If I rem that line out, it will trap out on the next statement that attempts to do a .SetFocus to some other control The error is 2110 "Can't move focus to control" and if I step through the code, the explanation that pops is "Macro or functi...

Delete records using listbox
Hi, Does anyone know a way of deleting selected records in a multi-selection list box? Thanks On Mon, 17 Dec 2007 08:19:00 -0800, s4 <s4@discussions.microsoft.com> wrote: There is no built-in way to do this, so you would have to write the code yourself. Iterate over the SelectedItems collection, and call a Delete query for each record. Alternatively you can replace the listbox by a subform, which supports automatic deletion. -Tom. >Hi, >Does anyone know a way of deleting selected records in a multi-selection >list box? >Thanks Assuming that the bound column of your l...

Listbox selected freezes the form
I'm using the following line in the form_open to select the first item in the list which susequently selects data in the second listbox: Me.lstDate.Selected(0) = True However the whole form freezes and nothing works? Any ideas? Many thanks ShariS "ShariS" <u40676@uwe> wrote in message news:7e4b3831704cd@uwe... > I'm using the following line in the form_open to select the first item in > the > list which susequently selects data in the second listbox: > > Me.lstDate.Selected(0) = True > > However the whole form freezes and nothing works? Any i...

Opendialog with Multiselect
Hello, i created a CFileDialog with mulitselect. But I can't select more than 5 or 6 files at the same time! Where is the problem??? Here is my code: CString szFilter; szFilter.Format("Bitmap (*.bmp)|*.bmp||"); CFileDialog OpenDialog(TRUE, "*.bmp", NULL, OFN_ALLOWMULTISELECT | OFN_NOCHANGEDIR, szFilter, this); POSITION ActualFile = OpenDialog.GetStartPosition(); while (NULL != ActualFile) { szFilename = OpenDialog.GetNextPathName(ActualFile); MessageBox(szFilename, "BMP"); } Another question: can i determine the number of the selected files...

Bill Summary, how can I multiselect each bill to see total at bott
In my previous version I could hold control and select each of my bills to see my projected balance. I can't do that anymore. Is there something else I need to do or has this function been removed? The latter. They put it in. They take it out. For some reason, they just don't like this feature. "jeaninel" <jeaninel@discussions.microsoft.com> wrote in message news:96617A57-86D7-4A3E-8F64-16A4EE16F228@microsoft.com... > In my previous version I could hold control and select each of my bills to > see my projected balance. I can't do that anymore. Is th...

Running a report on a filtered Listbox
I have a form that has a listbox wich displays a filtered table. I would like to print a report of the contents of that listbox. This seems like an easy task but I'm struggling here. Can you help? I want to show everything that is in the listbox. For example my list box contains a running list of items that need to be completed on a construction project. I have a combo box that has all the catagories for the items. If I select on type of item like "Work In Progress", the list box will show me a filter of only the "Work In Progress" items. I would like ...

ListBox Control, inserting values into col
hi everyone i inserted one List control in a dialog box. In List Control i given a 3 columns, i am unable to insert values in respective column. here i am using both "InsertItem" & "SetItemText" method to insert values, but whats happening here is only first column getting inserted into list control and remaining columns are not inserted. For first column value to insert i used "insertItem" Method, for remaining 2 columns i used "SetItemText" method. when i debug this and see the return value, the "SetItemText" method returns "0"...

How to show objects in a ListBox depedent of their state??
Hi, In my Documentclass is a list of Objects. This objectlist I want t display in a ListBox that sits on a CFormView, which is connected t the document class. Secondly it is necessary, that the ListBoxentrie are diplayed according to the status of the actual object. For exampl one ListBox-Entry shall be green and the other one shall be red.... I derived my own ListBox-Class and overwrote the drawItem()- an measureItem()-method, but I think, in these methods I should get acces to the actual object to be displayed....How can I do this??? I mean, filled the List with "m_ListBox.AddString...

Multicolumn listbox behaving wwird in VC7.1
Prob: Created a Listbox with Horizontal Scroll and Multicolumn property set to true. When you select any item in the columns say XCol other than the first column, the item in the XCol+1 column in the same row would be selected if XCol+1 exists else it would select the last item in the list. To be simple if you select 2 rwo item in the 2 Column, the 2 row element in the 3 column would be selected if 3column exists else it will select the last item in the list. It happens only when you select other than the first column for the first tim in the list. For subsequent selections it works fin...

Question about listbox selection
I have a listbox that has all item's in my database, I have next it to textbox's that I have for manual entry of information that goes into a table. This works good. Once the manual information is saved how do I get that listbox to automatically update itself upon new entry? Before update? Also since that listbox has all item's that were entered into the table, how do I select the choice in the listbox to bring up that one particular item number in the textbox's. To explain, even though I enter in the information in the textbox, i can scroll through them and see all the items, ...

Listbox row source and record locking?
I'm setting up my first true multi user database and I have a question on record locking. If I set a list box row source type to "table/query" and specify a select query for it, does Access lock those records? In the past I have always used "value/list" and loaded the records with code but it would be much easier to use ""table/query" if it does not lock the records. In most cases, Access only locks an editable record. The select statements in list and combo boxes do not lock the table because you aren't editing those records. ...

selected item in listbox turn red instead of black
How can I make the back color of the selected item in a listbox turn red instead of black when clicked? Thanks -- deb Is there a shorter version. That is a bit of overkill for what I need. I just want the selected item to turn red instead of black. Not each row a different color. Any other suggestions -- deb "Wayne-I-M" wrote: > Hi Deb > > Check the link > > http://www.lebans.com/listboxenhanced.htm > > Good luck > > -- > Wayne > Manchester, England. > > > > "deb" wrote: > > > > > How can ...

Is it possible to set a listbox column text to align right?
I have a listbox that has abount 14 columns. My client asked if I can make one of them (a money display with $ sign) to align right cos that makes it easier to read. I thought it is simple but it seems not possible. "yanguo" <yanguo@discussions.microsoft.com> wrote in message news:2A0FF66A-FFB2-490F-B5EE-4A36E3AED149@microsoft.com... >I have a listbox that has abount 14 columns. My client asked if I can make > one of them (a money display with $ sign) to align right cos that makes it > easier to read. I thought it is simple but it seems not possible. I haven'...

Listbox problem
I have a list box which I have set up which runs a message bank. I would like it to have the ability to delete the sected message from the worksheet. How can I do this? userform name is "splash" listbox1 its rowsource is messagesa2:a1000 and the button i wish to use to delete is commandbutton2 any help with the code would be great Thanks Greg Sorry posted same up top Greg "browie" <laptopgb@ihug.com.au> wrote in message news:deca44$qbu$1@lust.ihug.co.nz... >I have a list box which I have set up which runs a message bank. I would >like it to have...

Viewing expressions in a listbox 04-24-10
Access 2003, XP pro, semi-novice I have a table "Expression" where records are similar to the one below: [Adjective] & " " & [vehicle] & " is " & [color] [Adjective] & " " & [color] & " " & [vehicle] & " has a puncture" [Adjective] & " " & [vehicle] & " has a " & [color] & " stripe" I have another table "Word" similar to that below: WordID: 1 Adjective: My Vehicle: car Color: blue WordID: 2 Adjective: His Vehicle: bicy...