Results 1 to 6 of 6
  1. #1
    jagriffith is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    4

    Displaying only selected List Box items on report?

    I have a report with a series of combo boxes on it, then i have one list box. I want that one to, on the report, only display those values that are selected. (checked).

    Thanks,


    Jeremiah

  2. #2
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    I wouldn't display a listbox on a report....but a label with the selected values from the list box. I would add code to the report similar to this:

    Private Sub Report_Open(Cancel As Integer)


    Me.lblArgs.Caption = listB

    End Sub
    Private Function listB() As String
    Dim strList As String ' Where condition
    Dim lst As ListBox ' multiselect list box
    Dim vItem As Variant ' items in listbox
    Dim iLen As Integer ' length of string.
    Set lst = Forms![TopEmployers]!lstSource
    'loop through all items in listbox
    For Each vItem In lst.ItemsSelected
    If Not IsNull(vItem) Then
    strList = strList & lst.ItemData(vItem) & ";"
    End If
    Next
    listB = strList
    End Function

  3. #3
    jagriffith is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    4
    Where would you go about adding code to the report? I've added code to various items in access, but never to a report.

  4. #4
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    Add it to the on open event of the report. You'll find it on the property sheet.

  5. #5
    jagriffith is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    4

    Okay...

    Okay, i still couldn't get it to work. I did figure out where to put the code, and the code does attempt to run at start up, but it doesn't work. It comes up with a debug error on the set lst = command.

    I've set the command to Set lst = Forms!Machine_Orders![I- Special Option]

    Which is the Form, and the specific list box i am trying to access.

    Any ideas?

  6. #6
    jagriffith is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    4
    Nevermind! I'm a moron lol. I forgot, you can't call the form if you dont have it open! With the form open this works fine. I did change one thing, i changed from ";" to vbcrlf to cause it to insert a new line and drop the multiple selections down to a line each item. Now it works great! Thanks for your help!

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

Similar Threads

  1. Edit List Items
    By Broderhol in forum Forms
    Replies: 3
    Last Post: 02-23-2011, 05:51 PM
  2. Selected items in listbox
    By tomodachi in forum Access
    Replies: 1
    Last Post: 09-09-2010, 01:14 PM
  3. Replies: 1
    Last Post: 03-15-2010, 02:52 PM
  4. Highlighting Items in List Box from Table Data
    By swalsh84 in forum Programming
    Replies: 2
    Last Post: 01-25-2010, 08:55 AM
  5. list box items
    By thewabit in forum Forms
    Replies: 12
    Last Post: 01-01-2010, 08:59 PM

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 - Senior Forums