Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Am I missing something simple?

Posted on 2011-02-18
13
313 Views
Last Modified: 2012-05-11
Hi all, Not sure what is going on here, so any help would be appreciated.

I have a form in access 2003 with a list box control.  For the Double Click event I have the following code;

Dim i as Integer
For i = Me.ListBoxName.ListCount - 1 To 0 Step - 1
If Me.ListBoxName.Selected(i) Then Me.ListBoxName.RemoveItem i
Next i

This works perfectly.

The problem;

I have another form in the same database with a list box control with exactly the same code for the Double Click event, however it will remove multiple items at a time.  There is no multi select for either list box.

Got me stumped??
0
Comment
Question by:DockieBoy
  • 6
  • 5
  • 2
13 Comments
 
LVL 75
ID: 34931506
Can you upload the db?

mx
0
 
LVL 3

Author Comment

by:DockieBoy
ID: 34931515
It's in progress, just started and very messy, lol.  The forms with the list boxes in question are ZoneData and ControlEquipmentData
Bass.mdb
0
 
LVL 75
ID: 34931528
Which forms and how do I reproduce the issue ?

mx
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 3

Author Comment

by:DockieBoy
ID: 34931540
Open db normally, on the left hand side form click the sites button.  Check the "mon code" option button and type 1234 into the text box.  Press enter, select yes on the message box.  Click the button with the right arrow at the bottom right hand corner of the pop up form.  The Form will change to "Equipment Data".  Use the "Equipment Type" combo box to select an equipment type, enter some text in the "location text box" and hit enter.  This will add the item to the list box.  Add several items.  Double Click on items in various positions in the list box and watch the crazyness begin, lol.  If you use the button with the right arrow to navigate to the "Zone List" form, you can perform the same steps and see that it all works fine there.
0
 
LVL 75
ID: 34931561
Yeah ... I see the issue.  No apparent reason.

Here is my suggestion, since I have to sign off for the night.

Instead of the Double Click ... forget that ... and instead, add a Button next to the List box ... and use the same code.

I have a feeling this will fix the issue ... at least try this as a test.

mx
0
 
LVL 3

Author Comment

by:DockieBoy
ID: 34931577
Lol, crazy db!  Still same problem, i shall keep playing around and see what I can figure out.  Thanks for your help. :)
0
 
LVL 75
ID: 34931610
Really!  Damn.

Ok ... replace that list box with a new one.
And do a Compact and Repair on the db for good measure - delete that list box first - keep code in Notepad. Compact & Repair ... and a new list box and put code back in.

mx
0
 
LVL 3

Author Comment

by:DockieBoy
ID: 34931630
Still no good, this is strange.  Might have to code it differently.  It's not multi select so I can do it another way i guess.  :)
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 500 total points
ID: 34931758
Change your code to this

Dim i as Integer
For i = Me.ListBoxName.ListCount - 1 To 0 Step - 1
    If Me.ListBoxName.Selected(i)
        Me.ListBoxName.RemoveItem i
        EXIT FOR
    END IF
Next i

 
0
 
LVL 3

Author Comment

by:DockieBoy
ID: 34931786
Well I'll be.  Problem solved.  Thanks so much for your help.  Just out of curiosity though, any idea why it works on one list box but not another?
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34931862
Not a clue :P
0
 
LVL 3

Author Comment

by:DockieBoy
ID: 34931868
Lol, well that makes two of us.  Think I might change the code for the other one to prevent any future problems.
0
 
LVL 75
ID: 34931984
It's a timing issue with the list box and the double clicking ... a 2nd item actually gets selected while the loop is in progress.  The Exit For avoids that ... and I should have seen that.

mx
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question