Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006

    Unanswered: Read Multi Select List box Selections (Was ???)

    Need help!!
    I have two list box in a form with one command button.I want only one list box to be used.I want the second list box to be optional.I need some changes in my code.can somebody help me!Here is the code.

    Private Sub Open_Individual_Report_Click()
    On Error GoTo Open_Individual_Report_Error
    Dim Q As QueryDef, db As Database
    Dim Criteria As String
    Dim ctl As Control
    Dim Itm As Variant
    Dim Criteria5 As String
    Dim ctl5 As Control
    Dim Itm5 As Variant
    Dim strSQL As String
    Dim stDocName As String
    ' Build a list of the selections.
    Set ctl = Me![List31]
    For Each Itm In ctl.ItemsSelected
    If Len(Criteria) = 0 Then
    Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
    Criteria = Criteria & "," & Chr(34) & ctl.ItemData(Itm) _
    & Chr(34)
    End If
    Next Itm
    If Len(Criteria) = 0 Then
    Itm = MsgBox("You must select one or more items in the" & _
    " Assign_To list box!", 0, "Ooops")
    Exit Sub
    End If
    Set ctl5 = Me![List26]
    For Each Itm In ctl5.ItemsSelected
    If Len(Criteria5) = 0 Then
    Criteria5 = Chr(34) & ctl5.ItemData(Itm) & Chr(34)
    Criteria5 = Criteria5 & "," & Chr(34) & ctl5.ItemData(Itm) _
    & Chr(34)
    End If
    Next Itm
    If Len(Criteria5) = 0 Then
    Itm5 = MsgBox("You must select one or more items in the" & _
    " Category list box!", 0, "Ooops")
    Exit Sub
    End If
    Select Case Me.Status_Groupoption
    Case 1:
    Case 2: strSQL = " AND [Closed]<>-1"
    Case 3: strSQL = " AND [Closed]"
    End Select
    ' Modify the Query.
    Set db = CurrentDb()
    Set Q = db.QueryDefs("Query1")
    Q.SQL = "Select * From Data Where [Assign_To] IN(" & Criteria & ") AND Category IN(" & Criteria5 & ")" & strSQL & ";"
    ' Run the query.
    'DoCmd.OpenQuery "Query1"
    stDocName = "StaffTotalActivity"
    DoCmd.OpenReport stDocName, acPreview
    Exit Sub
    Select Case Err
    Case 3075
    MsgBox "Please enter the dates you wish to search between.", 0, "Ooops"
    Case Else
    MsgBox Error, vbCritical, "Error: " & Err
    End Select
    Resume Open_Individual_Report_Exit
    End Sub
    Last edited by loquin; 08-17-06 at 12:28. Reason: add [code] [/code] tags to improve readability

  2. #2
    Join Date
    Feb 2004
    One Flump in One Place
    Hi Napoli

    There's a lot of code and not much explanation

    Please could you just run through what you would like to happen and what is going wrong with your current code
    pootle flump
    ur codings are working excelent.

Posting Permissions

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