Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2010
    Posts
    9

    Question Unanswered: Problem with List Box - Microsoft Access (2003)

    Microsoft Access - version 2003

    Hi everyone, I have a list box with the following code directly associated with a button. When I run the report, the results are fine. My problem is that when I press the button to run the report, I get a parameter window for the dates, which is okay, but then I get more parameter windows for each employee I selected in the drop-down list. Can someone help me eliminate the employee parameter windows for each employee selected upon runtime???

    THANK YOU VERY MUCH



    Private Sub BTN_EMPLOYEE_Click()
    Dim strEmployee As String
    Dim varItem As Variant

    'make sure a selection has been made
    If Me.LIST_EMPLOYEE.ItemsSelected.Count = 0 Then
    MsgBox "Must select at least 1 employee"
    Exit Sub
    End If

    'add selected values to string
    For Each varItem In Me.LIST_EMPLOYEE.ItemsSelected
    strEmployee = strEmployee & Me.LIST_EMPLOYEE.ItemData(varItem) & ","

    'Use this line if your value is text
    strEmployee = strEmployee & "'" & Me.LIST_EMPLOYEE.ItemData(varItem) & "',"
    Next varItem

    'trim trailing comma
    strEmployee = Left(strEmployee, Len(strEmployee) - 1)

    'open the report, restricted to the selected items
    DoCmd.OpenReport "R_HOURS_EMPLOYEE", acPreview, , "NUID IN(" & strEmployee & ")"

    End Sub

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Each employee name should be surrounded by single quotes:
    Code:
    For Each varItem In Me.LIST_EMPLOYEE.ItemsSelected
        If Len(strEmployee) > 0 then strEmployee = strEmployee & ", "
        strEmployee = strEmployee & "'" & Me.LIST_EMPLOYEE.ItemData(varItem) & "'"
    Next varItem
    Have a nice day!

Posting Permissions

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