Removing Items from Listbox

I have a listbox on a form and I want the user to be able to select the items 
to be removed from the list.  But when I use the RemoveItem method on the 
first selected row, all the other items in the list become UNselected and 
therefore don't get removed.  Can anyone help?
Thanks in advance,
-- 
Glenn
0
Utf
10/18/2007 12:14:00 PM
access.formscoding 7493 articles. 0 followers. Follow

4 Replies
695 Views

Similar Articles

[PageSpeed] 24

By the way, I tried two different approaches with the same result.

#1
Dim lb               As ListBox
Dim varItem          As Variant
For Each varItem In lb.ItemsSelected
    lb.RemoveItem Index:=varItem
Next varItem

#2
    dim i as Integer
    dim intIndex as Integer
    dim lb as ListBox
    For i = lngItemCount - 1 To 0 Step -1
        If lb.Selected(i) = True Then
            intIndex = i
            lb.RemoveItem Index:=intIndex
        End If
    Next i

-- 
Glenn


"Glenn Suggs" wrote:

> I have a listbox on a form and I want the user to be able to select the items 
> to be removed from the list.  But when I use the RemoveItem method on the 
> first selected row, all the other items in the list become UNselected and 
> therefore don't get removed.  Can anyone help?
> Thanks in advance,
> -- 
> Glenn
0
Utf
10/18/2007 12:20:01 PM
Untested, but should work:

Dim lb As ListBox
Dim varItem As Variant
Dim lngSelected() As Long
Dim lngLoop As Long

  If lb.ItemsSelected.Count > 0 Then
    ReDim lngSelected(lb.ItemsSelected.Count - 1)
    lngLoop = 0
    For Each varItem In lb.ItemsSelected
      lngSelected(lngLoop) = varItem
      lngLoop = lngLoop + 1
    Next varItem
    For lngLoop = UBound(lngSelected) To 0 Step -1
      lb.RemoveItem Index:=lngLoop
    Next lngLoop
  End If

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Glenn Suggs" <GlennSuggs@discussions.microsoft.com> wrote in message 
news:D050357D-D5C2-46E0-8D12-F37094000FE0@microsoft.com...
> By the way, I tried two different approaches with the same result.
>
> #1
> Dim lb               As ListBox
> Dim varItem          As Variant
> For Each varItem In lb.ItemsSelected
>    lb.RemoveItem Index:=varItem
> Next varItem
>
> #2
>    dim i as Integer
>    dim intIndex as Integer
>    dim lb as ListBox
>    For i = lngItemCount - 1 To 0 Step -1
>        If lb.Selected(i) = True Then
>            intIndex = i
>            lb.RemoveItem Index:=intIndex
>        End If
>    Next i
>
> -- 
> Glenn
>
>
> "Glenn Suggs" wrote:
>
>> I have a listbox on a form and I want the user to be able to select the 
>> items
>> to be removed from the list.  But when I use the RemoveItem method on the
>> first selected row, all the other items in the list become UNselected and
>> therefore don't get removed.  Can anyone help?
>> Thanks in advance,
>> -- 
>> Glenn 


0
Douglas
10/18/2007 1:14:43 PM
Doug:

Thanks for the response.  There was just one thing I had to change in your 
code for this to work.  The line:

lb.RemoveItem Index:=lngLoop      

didn't remove the correct row.  It had be

lb.RemoveItem Index:=lngSelected(lngLoop)

because the index value was stored in the array lngSelected and the variable 
lngLoop was the index to THAT array.  But let me ask you one more thing, 
please.  How could I access one of the two fields in the row for the selected 
items.  I need to do something else with a piece of the data in addition to 
removing it from the list.  Specifically the field in Column(0).
Thanks again,
-- 
Glenn


"Douglas J. Steele" wrote:

> Untested, but should work:
> 
> Dim lb As ListBox
> Dim varItem As Variant
> Dim lngSelected() As Long
> Dim lngLoop As Long
> 
>   If lb.ItemsSelected.Count > 0 Then
>     ReDim lngSelected(lb.ItemsSelected.Count - 1)
>     lngLoop = 0
>     For Each varItem In lb.ItemsSelected
>       lngSelected(lngLoop) = varItem
>       lngLoop = lngLoop + 1
>     Next varItem
>     For lngLoop = UBound(lngSelected) To 0 Step -1
>       lb.RemoveItem Index:=lngLoop
>     Next lngLoop
>   End If
> 
> -- 
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
> 
> 
> "Glenn Suggs" <GlennSuggs@discussions.microsoft.com> wrote in message 
> news:D050357D-D5C2-46E0-8D12-F37094000FE0@microsoft.com...
> > By the way, I tried two different approaches with the same result.
> >
> > #1
> > Dim lb               As ListBox
> > Dim varItem          As Variant
> > For Each varItem In lb.ItemsSelected
> >    lb.RemoveItem Index:=varItem
> > Next varItem
> >
> > #2
> >    dim i as Integer
> >    dim intIndex as Integer
> >    dim lb as ListBox
> >    For i = lngItemCount - 1 To 0 Step -1
> >        If lb.Selected(i) = True Then
> >            intIndex = i
> >            lb.RemoveItem Index:=intIndex
> >        End If
> >    Next i
> >
> > -- 
> > Glenn
> >
> >
> > "Glenn Suggs" wrote:
> >
> >> I have a listbox on a form and I want the user to be able to select the 
> >> items
> >> to be removed from the list.  But when I use the RemoveItem method on the
> >> first selected row, all the other items in the list become UNselected and
> >> therefore don't get removed.  Can anyone help?
> >> Thanks in advance,
> >> -- 
> >> Glenn 
> 
> 
> 
0
Utf
10/18/2007 2:26:03 PM
Not sure I understand your question.

If you're asking how to refer to the first column of an arbitray row in the 
list box, it's

Me!NameOfListbox.Column(0, Rownumber)

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Glenn Suggs" <GlennSuggs@discussions.microsoft.com> wrote in message 
news:B4FB4106-C1A4-4563-9F9C-CD9DC230FC5D@microsoft.com...
> Doug:
>
> Thanks for the response.  There was just one thing I had to change in your
> code for this to work.  The line:
>
> lb.RemoveItem Index:=lngLoop
>
> didn't remove the correct row.  It had be
>
> lb.RemoveItem Index:=lngSelected(lngLoop)
>
> because the index value was stored in the array lngSelected and the 
> variable
> lngLoop was the index to THAT array.  But let me ask you one more thing,
> please.  How could I access one of the two fields in the row for the 
> selected
> items.  I need to do something else with a piece of the data in addition 
> to
> removing it from the list.  Specifically the field in Column(0).
> Thanks again,
> -- 
> Glenn
>
>
> "Douglas J. Steele" wrote:
>
>> Untested, but should work:
>>
>> Dim lb As ListBox
>> Dim varItem As Variant
>> Dim lngSelected() As Long
>> Dim lngLoop As Long
>>
>>   If lb.ItemsSelected.Count > 0 Then
>>     ReDim lngSelected(lb.ItemsSelected.Count - 1)
>>     lngLoop = 0
>>     For Each varItem In lb.ItemsSelected
>>       lngSelected(lngLoop) = varItem
>>       lngLoop = lngLoop + 1
>>     Next varItem
>>     For lngLoop = UBound(lngSelected) To 0 Step -1
>>       lb.RemoveItem Index:=lngLoop
>>     Next lngLoop
>>   End If
>>
>> -- 
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Glenn Suggs" <GlennSuggs@discussions.microsoft.com> wrote in message
>> news:D050357D-D5C2-46E0-8D12-F37094000FE0@microsoft.com...
>> > By the way, I tried two different approaches with the same result.
>> >
>> > #1
>> > Dim lb               As ListBox
>> > Dim varItem          As Variant
>> > For Each varItem In lb.ItemsSelected
>> >    lb.RemoveItem Index:=varItem
>> > Next varItem
>> >
>> > #2
>> >    dim i as Integer
>> >    dim intIndex as Integer
>> >    dim lb as ListBox
>> >    For i = lngItemCount - 1 To 0 Step -1
>> >        If lb.Selected(i) = True Then
>> >            intIndex = i
>> >            lb.RemoveItem Index:=intIndex
>> >        End If
>> >    Next i
>> >
>> > -- 
>> > Glenn
>> >
>> >
>> > "Glenn Suggs" wrote:
>> >
>> >> I have a listbox on a form and I want the user to be able to select 
>> >> the
>> >> items
>> >> to be removed from the list.  But when I use the RemoveItem method on 
>> >> the
>> >> first selected row, all the other items in the list become UNselected 
>> >> and
>> >> therefore don't get removed.  Can anyone help?
>> >> Thanks in advance,
>> >> -- 
>> >> Glenn
>>
>>
>> 


0
Douglas
10/18/2007 5:32:32 PM
Reply:

Similar Artilces:

Removing filing extension from header
I prepare financial statements that contain between 10 and 3 worksheets. I would name the file "March 31, 2005" and use the fil name function in the header to have "March 31, 2005" appear on eac worksheet. When I used Excel 2000, the header would read "March 31 2005". After I upgraded to Excel 2003, the header now reads "March 31 2005.xls". Is there any way to remove the .xls extension from the header. I woul hate to have to manually enter a date on each worksheet. Thanks, Mar -- fixcp ---------------------------------------------------------------...

RE: How do I get my new dialog box to invoke when I press New Menu Item
Hi All, 1. Machine and OS specifications I have Windows XP running Office XP Standard Edition. These software packages are installed on my dell Inspiron laptop. I have 128 MB RAM with a 40 GB HardDrive. 2. Problem In excel, when I pressed the New menu item, a dialog box would appear displaying all of the known templates. Now, only a new worksheet appears. I would like for the dialog to appear again. Can someone tell me how to get the dialog box back displaying all of my templates? d, The default New button has always generated a new workbook, no dialog box. There's ano...

attachments to calendar item scheduled by someone else
How does one add information/attachments to a calendar item scheduled by someone else so that the information/attachments are not lost when the meeting is updated by the organizer? Thanks, Barb ...

"Cannot start outlook. Could not open the item" appears on start.
When I try to open outlook I get the messeage "Cannot open microsoft outlook. Could not find the item." I have tried uninstalling and reinstalling. I've never had this problem before and don't know what to do. Can someone help? Janetto <Janetto@discussions.microsoft.com> wrote: > When I try to open outlook I get the messeage "Cannot open microsoft > outlook. Could not find the item." I have tried uninstalling and > reinstalling. I've never had this problem before and don't know what > to do. Can someone help? Have you created a...

how do i remove box around clip art
how do i paste just the picture subject and not the background of a picture from clip art? trying to remove the box that comes up around it. If the clipart is .wmf the box is transparent, but if you must remove it, select the clipart, arrange, ungroup.(You may have to ungroup twice). If the clips are bitmaps, use the transparency tool on the picture toolbar to make the background transparent. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "kklupar" <kklupar@discussions.microsoft.com> wrote in message news:13E8DF0D...

Edit List Item in Access 2007
I have been adding the new values into item list for the past few days, but when I continue to do so today, all the values are keyed into the list but not able to save in the list after clicking 'OK'. Any reason for this sudden change? Appreciate your kind response... Thanks & regards, Lawrence Just an idea When you say > I have been adding the new values into item list for the past few days this sounds like you should not be using a list - are you adding zillions on items??. You could change it to a form/datasheet view and add controls to select items. O...

WHY select the first item didn't receive OnPaint in LISTCTRL!
hello everyone, I write a custom listctrl inherit from the CListCtrl( MFC ). I don't use CUSTOMDRAW and OWNDRAW, and rewrite the OnPaint fucntion. The OnPaint function like this: void CListCtrlST::OnPaint() { CPaintDC dc(this); // device context for painting ///////////////////////////////////////////////// CRect rtList; GetClientRect( &rtList ); CDC* pDC = &dc; CMemDC memDC( pDC, &rtList ); // double buffer..... memDC.SetBkMode( TRANSPARENT ); // don't use the system paint, because it's too slow... // if you resize the listctrl...

Corrupted "deleted Item" folder in microsoft outlook 2000
Hi all, I have this spam mail in my deleted item folder which i am not able to delete it away. When i tried to delete it, open it, move it to other folder etc ... outlook 2000 will have an error and will close down and i have to restart it. I tried lots of methods suggested by some nice people in here but stil it doesnt work. Is there any way or how can i have a whole new "deleted item" folder without losing my other folders and emails as well ?? Pls help.... thanksss Yes, per personal experience. Make a new PST, even customize the name of it for yourself. Make it the def...

Item
Item needs to have more customer fields. Some countries require both an Inc and Ex Cost of each item. Ib Ivan, What are Inc and Ex costs and are you asking for more custom fields or do you really mean customer fields? -- * "Ivan Brebner" <ibrebner@premiumretail.com.au> wrote in message news:Oo9hLB4%23FHA.2524@TK2MSFTNGP10.phx.gbl... Item needs to have more customer fields. Some countries require both an Inc and Ex Cost of each item. Ib In places like Australia retailers prefer to see the cost of an item including tax as well as Excluding. So that quoting ite...

Remove BP tables from Dynamics database
I have a client who is currently running GP 8. I will be upgrading them to GP 10. Back when GP 8 was installed they installed but never used BP. So now the Dynamics database has BP tables in it. I want to completely remove all the BP 2.5 tables so that when I come along to install BP for GP 10 it does not run into any of those old useless BP tables. What is the best way to remove all of the old BP tables? The article 862544 in CustomerSource below includes scripts that should remove the BP SQL objects How to remove Business Portal 2.x https://mbs.microsoft.com/knowledgebase/KbDisplay....

Automatically delete old items off the server?
Is there any way we can delete old items from the server itself? Sure, we can use policies on Outlook, but many of our users are just using OWA and we want their old email to get deleted after 120 days. Any way this can be done? TIA! / Per Use Recipient Policy with Mailbox Manager settings. Recommend using this in "generate report only" mode till you're confident the policy has picked up the right users, is doing/will do what you want it to do, and users are informed about this (so they have time to backup/archive their stuff). -- Bharat Suneja MVP - Exchange www.zen...

Accurate Gross Margin Tracking on Variable Cost Items
GP 8.0 We custom order products. We use a fixed SKU for the product because it is custom ordered in different sizes and colors. Each order has a different cost. How can we set it up so that we have accurate gross margin information on the sale? Basically we would like to type in the cost on the sales order so we know exactly what the GM is. We enter the cost in the purchase order (which we generate via SOP to POP), but it appears that the cost isn't reflected until the next Sales Order so our GM tracking on a per order basis is completely off. Thanks, Jason ...

Removing table column buttons?
Is there a way to remove the sort/filter buttons from specific columns in an Excel 2007 table? Our tables have certain columns that are very narrow and that we will never need to be sorted or filtered. Furthermore, the buttons cover-up the heading labels in those columns. Is there a way to manually disable the sort/filter feature for specific columns and remove the buttons? We also notice that converting a range to a table often changes the column size, especially of smaller columns. Is there a way to prevent this behavior? Thank you for any help with these items. a couple thing...

How to remove space/gap after hide a field
Hi, How can I remove space/gap after hide a field? I am using crmForm.all.fieldname_c.style.display = 'none'; crmForm.all.fieldname_d.style.display = 'none'; Thanks -- MS CRM consultants at Melbourne Visit my CRM blog at http://melbournecrm.spaces.live.com/ ...

Out to remove entries from the quick fill list..
Outlookers, When you create a new email message in Outlook and type a character in the "To:" field, Outlook immediately pops up with a quick list of all the names that match the character. In my case, I have one person with two email addresses: bob (bob@xyc.com) bob (bob@abc.com) I am used to just typing "bob" and sending the email out. As a result, the email ends up going to Bob's home (the first email address) and that is not desirable. How do I get rid of the first entry altogether? This entry is definitely not in my address book. It appears each time an emai...

1 item need to be tax inclusive
I have a customer that wants to sell CDs for $13.00 even, including the tax. However because the taxation is setup for be tax exclusive and the tax percentage being 9.75% we cannot get the CD to come up exactly $13.00. We either get $13.01 or $12.99. Any hints? what if you set the price to $11.84 and the tax to 9.797% "Phil V" wrote: > I have a customer that wants to sell CDs for $13.00 even, including the tax. > However because the taxation is setup for be tax exclusive and the tax > percentage being 9.75% we cannot get the CD to come up exactly $13.00. ...

Line items in an Invoice, disappear
Hi, Using SOP, some times the line items in an Invoice, which has been transfered from on order, just disappear. I tried doing the check links, but the line items do not come back, except that the totals for the invoices are set back to zero. any suggestions? please advice Sajid Saeed ...

English and Chinese in the Item Description
Requirement: The client is planning to deploy GP, howver the following is the requirement: When they set up inventory items we need to be able to use one of the Item Description fields to list the Chinese description of the item. My goal was to have both English and Chinese in the Item Description and Short Name fields and then modify any reports to list both the Description and Short Name fields. I tested by using English in the description field and attempting to type traditional Chinese fonts in the Short Description field. GP does not display the Chinese fonts in the Short Name fi...

need to remove the cycle of import tasks in team member side
In project server 2007 we have timesheet entry workflow. which is Team Member --> TimeSheet Manager -----> Team Member (which import tasks and then submit again to Project Manager) Our company needs that team member dont need to import tasks . when he submit to timesheet manager then Timesheet manager approve and import tasks and then sent to project manager. company dont want the team member import and sent to project manager . how to remove this cycle . Kindly reply me soon Sam -- There is no default way in Project Server 2007 to meet your reporting requirements. ...

When I send emails, they aren't appearing in the sent items folde.
Kerrie <Kerrie@discussions.microsoft.com> wrote: Have you enabled the option to save sent messages in the Sent Items folder? -- Brian Tillman Have you checked the view in your Sent Items folder? Make sure it's not set to Unread Messages. Patricia Cardoza Outlook MVP Author - Special Edition Using Microsoft Office Outlook 2003 Lead Author - Access 2003 VBA Programmer's Reference Author - Absolute Beginner's Guide to Microsoft OneNote 2003 http://blogs.officezealot.com/cardoza > > > ...

Cant open item (routed mail)
-- We have experienced issues with 6 users on our exchange 2003 system (clients are 2002 sp2) where they cannot open some items from their inbox. Outlook returns a "Can't open this item" error message. This error affects 6 of 100 users on the exchange and ONLY emails where: A) Email is forwarded (doesn’t affect new emails) AND B) email has routed from another domain to our domain using the deliver to alternative user option. This error has only begun since the mailboxes were migrated from Exchange 5.5 using ExMerge Can anyone assist? Michelle ...

Hot to prevent copy/paste of items in public folder
We have an application that uses Exchange public folders. I need to prevent users from using copy/paste (edit|copy, edit|paste, ctrl+c, ctrl+v) on the messages in these folders. They are doing this from the folder view. We a custom form associated with each of these folders. There is code the form which prevents in-cell editting by detecting when an item_write event fires when there was no previous item_read event. Unfortunately these form events do not fire when users copy/paste items. Is there any way to prevent the copy/paste? Thanks, Tony ...

I need to remove characters ...
I have a column of data that I wish to remove the first 2 characters from. Is there a way to quickly do this? Below is the sample data. Thank you, Rick c1122115 c1122116 c1122117 c1122118 c1122119 c1122120 c1122121 D1250592 D1250593 D1250594 D1250595 D1250596 D1250597 D1250598 You could insert a column and use this formula in that cloumn and drag it down then copy and paste values. =VALUE(MID(A1,2,8)) "Rick" wrote: > I have a column of data that I wish to remove the first 2 characters from. > Is there a way to quickly do this? Below is the sample data. > >...

Procedure to remove all named ranges #2
Don, Thanks for the tips great stuff!!! One question why is it that when w email this sheet that now has no code named ranges or objects that it i prompting the user to enable/disable macros when opening it? There i nothing but text and a couple of our embedded pictures in it. Funny thing is that if you open the attachment and save it to a folde then reopen it later it does not prompt you to enable/disable macros -- Doctor ----------------------------------------------------------------------- DoctorV's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=514 View t...

remove quote marks around email recepient
Does anyone know how in Outlook 2003 to get rid of the quote marks around a recipients name when you reply to a message? The problem is that this sent mail does not get ordered properly in the SENT MAIL folder since it now starts with a quote mark. ...