Results 1 to 3 of 3

Thread: [RESOLVED] Selecting Multiple Items in a Listbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Resolved [RESOLVED] Selecting Multiple Items in a Listbox

    I am having trouble with allowing users to select multiple items in a Listbox and then allowing them to be removed after clicking a "Verify" button. If multiple items were selected, only the first selected item would be removed from the listbox after selecting the "Verify" button. The other selected items would be still highlighted. Any suggestions?

    Here's the code for the verify button:

    VB Code:
    1. '*CMDVERIFY_CLICK()************************************************************
    2. 'NAME: cmdVerify_Click()
    3. 'DESC: Allows the user to verify that they have counted the selected item(s).
    4. Private Sub cmdVerify_Click()
    5.     Set connection = New ADODB.connection
    6.     connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    7.         "Data Source= G:\Finance\Inventory Control\CycleCount\DB\cycleCount.mdb"
    8.     connection.Open
    9.     Set recordSet = New ADODB.recordSet
    10.    
    11.     Dim counter As Integer
    12.     counter = lstVerificationScreen.ListCount - 1
    13.     Do While counter >= 0
    14.         If (lstVerificationScreen.Selected(counter) = True) Then
    15.  
    16.             Dim selectStatement, sSQL As String
    17.             Dim strArray() As String
    18.             strArray = Split(lstVerificationScreen.List(counter), vbTab, -1, 1)
    19.                                
    20.             selectStatement = "SELECT * " & _
    21.                               "FROM [MAIN] " & _
    22.                               "WHERE ID=" & strArray(0)
    23.            
    24.             sSQL = "UPDATE [ALTER] SET TYPEOFCHANGE='DELETED' " & _
    25.                    "WHERE [MAIN ID]='" & strArray(0) & "'"
    26.             connection.Execute sSQL
    27.            
    28.             sSQL = "UPDATE TOGO AS t SET CHECKED = TRUE" & _
    29.                    "WHERE PROD = '" & strArray(0) & "'"
    30.            
    31.             recordSet.Open selectStatement, connection
    32.            
    33.             If (recordSet.RecordCount = 1) Then
    34.                 selectStatement = "DELETE FROM [MAIN] WHERE ID=" & strArray(0)
    35.                 connection.Execute selectStatement
    36.             End If
    37.  
    38.             lstVerificationScreen.RemoveItem (counter)
    39.            
    40.            
    41.         End If
    42.         DoEvents
    43.         counter = counter - 1
    44.     Loop
    45.        
    46.     connection.Close
    47.     Set recordSet = Nothing
    48.     Set connection = Nothing
    49.    
    50. End Sub
    51. '*ENDOF*CMDVERIFY_CLICK()******************************************************

    Thank you.

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Selecting Multiple Items in a Listbox

    Is the ListBox updated/refreshed from the database after cmdVerify has executed?

    Three things I noticed.

    The Main.ID field is treated as numeric data, while the Alter.Main_Id and Togo.Prod fields are treated as string data. Is that correct?

    If (recordSet.RecordCount = 1) Then
    What if RecordCount is > 1 or -1 (which is possible)?

    The second update statement is never executed!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Selecting Multiple Items in a Listbox

    How do you update/refresh the data from the database after cmdVerify has executed?

    The Main.ID field is numeric; however, the Alter.Main_Id field is not. Togo.Prod field was corrected to be treated like a number. Thanks for pointing that out.

    In this statement I'm checking if the data is currently in the database as the database is refreshed daily. So if someone selects an item and counts it that day it will be in the database, but if not it will not be in the database. The data is refreshed daily since there is no primary key on the database where the information comes from thus no way to correctly update the existing data. I unfortunately have no control over that aspect.

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width