Results 1 to 9 of 9
  1. #1
    Atoga is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    21

    Listbox Selections to appear on Reports


    Hello All,
    I created reports in my database that are run by multiple selections from multiple listboxes. How can I make the selections appear on the reports in the Title or anywhere else on the report so that the user can see what criteria that actual report is based on?
    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How are you doing it? With this method:

    http://www.baldyweb.com/multiselect.htm

    the string could be passed in OpenArgs and displayed on the report.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Atoga is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    21
    Thanks. I am using 5 multi select lisboxes to create the reports (and there are five type of reports). Is there an easier way? It would be quite complicated to write this code because of the number of listboxes and reports....

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Just exactly how are you using multi-select listboxes to create reports?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Atoga is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    21
    For example I use this code to generate an Employee list based on multiple selections from 5 listboxes.

    Private Sub cmdEmpl_Click()


    Dim x As Long

    ' clear out old list selections

    DoCmd.RunSQL ("Delete * from t_Employee")
    DoCmd.RunSQL ("Delete * from t_Department")
    DoCmd.RunSQL ("Delete * from t_State")
    DoCmd.RunSQL ("Delete * from t_CourseQualification")
    DoCmd.RunSQL ("Delete * from t_Skill")

    If Me.lstEmployee.ItemsSelected.Count > 0 Then
    Me.lstEmployee.Value = Null
    End If

    Dim lngRow As Long
    If Me.lstDepartment.ItemsSelected.Count = 0 Then
    For lngRow = 0 To lstDepartment.ListCount - 1
    lstDepartment.Selected(lngRow) = True
    Next
    SelectAll = True
    End If


    If Me.lstCourseQualification.ItemsSelected.Count = 0 Then
    For lngRow = 0 To lstCourseQualification.ListCount - 1
    lstCourseQualification.Selected(lngRow) = True
    Next
    SelectAll = True
    End If

    If Me.lstState.ItemsSelected.Count = 0 Then
    For lngRow = 0 To lstState.ListCount - 1
    lstState.Selected(lngRow) = True
    Next
    SelectAll = True
    End If

    If Me.lstSkill.ItemsSelected.Count = 0 Then
    For lngRow = 0 To lstSkill.ListCount - 1
    lstSkill.Selected(lngRow) = True
    Next
    SelectAll = True
    End If

    'Add a for loop here for each list box


    For x = 0 To Me.lstDepartment.ListCount - 1
    If Me.lstDepartment.Selected(x) = True Then
    DoCmd.RunSQL ("Insert into t_Department (Department) values ('" & _
    Me.lstDepartment.ItemData(x) & "')")
    End If
    Next x

    For x = 0 To Me.lstState.ListCount - 1
    If Me.lstState.Selected(x) = True Then
    DoCmd.RunSQL ("Insert into t_State (State) values ('" & _
    Me.lstState.ItemData(x) & "')")
    End If
    Next x

    For x = 0 To Me.lstCourseQualification.ListCount - 1
    If Me.lstCourseQualification.Selected(x) = True Then
    DoCmd.RunSQL ("Insert into t_CourseQualification (CourseQualificationID) values ('" & _
    Me.lstCourseQualification.ItemData(x) & "')")
    End If
    Next x

    For x = 0 To Me.lstSkill.ListCount - 1
    If Me.lstSkill.Selected(x) = True Then
    DoCmd.RunSQL ("Insert into t_Skill (SkillID) values ('" & _
    Me.lstSkill.ItemData(x) & "')")
    End If
    Next x

    DoCmd.OpenReport "rptbyEmpl", acViewPreview, "", "", acNormal

    cmdPrint_Click_Exit:
    Exit Sub


    cmdPrint_Click_Err:
    MsgBox Error$
    Resume cmdPrint_Click_Exit

    End Sub

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Wow, you're populating temp tables with the data? Selecting all items in a listbox if none were selected? That seems much more complicated than what I would do, but how would you present the selections when selecting all? It would seem to be very cumbersome to list all states, etc. In any case, you could populate public variables within the same loops that do the inserts, and use those variables on your report to show the selections (via functions that return the values of the variables).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Atoga is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    21
    Yes, I was not able to find another way to create the reports based on multiple selections from multiple listboxes than with temp tables....maybe there is a simpler way...
    I assume users want to see all when they don`t select any as they surely don`t want to see none (then there is no data to show at all). Instead of pop-up asking them to select at least one, I just select all instead of them (assuming they don`t want to filter on that variable).
    As for presenting the selections on the reports, maybe I just leave it out...too cumbersome and yes, u are right, descriptions would be too long if for example many courses are selected...
    thanks anyway!

  8. #8
    Atoga is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Mar 2015
    Posts
    21
    How can I make a text box on the report display `Selected` in case not all items are selected from a listbox in the form? I decided that I would like to show on the report if there have been filtering applied to that variable (i.e. not all items were selected from the listbox), but the actual filter values I don`t want to display (might be too long). On the form I have Select All buttons next to each list...so maybe instruct the textbox to display `Selected` in case the SelectAll is not True?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Several ways to pass value to report.

    1. textbox on report references textbox on form
    2. form/report OpenArgs
    3. TempVars
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-29-2015, 04:02 PM
  2. Replies: 2
    Last Post: 02-01-2013, 05:23 PM
  3. Replies: 9
    Last Post: 05-23-2011, 06:12 PM
  4. projects database save listbox selections
    By taya621 in forum Access
    Replies: 33
    Last Post: 01-21-2011, 10:56 AM
  5. Replies: 9
    Last Post: 01-20-2011, 02:22 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums