Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With Listbox

Status
Not open for further replies.

mo2783

Programmer
Nov 16, 2003
68
GB
Hi

I have a 2 list Box, Which i can populate without any problems and move data between them.

I am having problems with the following code, where i am trying to display the results of the Applications installed on a specific Computer on the lstSoftwareLoaded listbox and those Applications that are not installed on the computer to show on the lstAppAvailable.

For Example

lstAppAvailable lstSoftwareLoaded
MS OFFICE 2003 > Windows Vista
Windows XP < OutLook Express

So the above lists would be displayed when a computer is selected from a drop down list showing all the Software available for insatlling and all the software that is installed on that specific machine.



Code:
Public Sub DisplayAllComputerDetails(ByRef rsDisplayComputerDetails As DAO.Recordset, ByRef frmAddComputer As Form, ByRef lstSotwareLoaded As ListBox, ByRef lstSoftwareAvailable As ListBox)

    With rsDisplayComputerDetails
        .MoveFirst
        frmAddComputer.cmbMake = .Fields("Computer_ID_Make")
        frmAddComputer.txtModel = .Fields("Computer_ID_Model")
        frmAddComputer.txtSerialNumber = .Fields("Computer_ID_Serial_Number")
        frmAddComputer.txtWarrantyExpiry = .Fields("Computer_ID_Warranty_Expiry")
        
        Do
            lstSotwareLoaded.AddItem .Fields("Application")
            
                Dim i As Integer
                Dim RemoveQueue() As Boolean
                ReDim RemoveQueue(0 To lstSotwareLoaded.ListCount - 1)

                For i = lstSotwareLoaded.ListCount - 1 To 0 Step -1
                    If lstSotwareLoaded.ListIndex Then
                        'Me.lstAppAvailable.AddItem lstAppsInstalled.ItemData(i)
                        RemoveQueue(i) = True
                    End If
                Next i

                For i = UBound(RemoveQueue) To 0 Step -1
                    If RemoveQueue(i) Then
                        lstSoftwareAvailable.RemoveItem i
                    End If
                Next i
            
            

            .MoveNext
        Loop Until .EOF
        
    End With


Any help would be much appreciated.

Thanks

Mo
 
Update:

I have it woking to an extent with the following code, What i need to do is check which items are in the installed list and remove them from the Available list any ideas how to check that?


Code:
Public Sub DisplayAllComputerDetails(ByRef rsDisplayComputerDetails As DAO.Recordset, ByRef frmAddComputer As Form, ByRef lstSotwareLoaded As ListBox, ByRef lstSoftwareAvailable As ListBox)

    Dim i As Integer

    With rsDisplayComputerDetails
        .MoveFirst
        frmAddComputer.cmbMake = .Fields("Computer_ID_Make")
        frmAddComputer.txtModel = .Fields("Computer_ID_Model")
        frmAddComputer.txtSerialNumber = .Fields("Computer_ID_Serial_Number")
        frmAddComputer.txtWarrantyExpiry = .Fields("Computer_ID_Warranty_Expiry")
        
        Do
            lstSotwareLoaded.AddItem .Fields("Application")
                        
            For i = lstSotwareLoaded.ListCount - 1 To 0 Step -1
                If lstSoftwareAvailable.ListCount - 1 Then
                    lstSoftwareAvailable.RemoveItem i
                End If
            Next i
        .MoveNext
        Loop Until .EOF
        
    End With


End Sub
 
Seems overly complicated. You should simply be able to do this is in sql with two queries and requery the listboxes as you add and remove items from the selected items.

To return the available apps something like.
Select appID, field 2, fieldN from someTable where appID NOT IN (some query returning the selected apps or a concatenated string of selected values)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top