Results 1 to 2 of 2
  1. #1
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55

    Open report from multi-select list box

    Hello and thank you in advance for any attention this post may receive.

    I am running MS Access 2010 on Windows XP and my access skills are limited.

    So I have a db with tables, forms and reports and would like to give my users the option of opening a filtered report (from a form).

    The form (frmSelectStatus) and report (rptStatus) have been created and both open correctly by normal selection from the 'All Access Objects' side bar.

    frmSelectStatus has a multi-select list box (lstStatus) and a command button (cmdStatus). When I click cmdStatus i get the correct report opening but it is all status records and not filtered by the selection made in lstStatus - and i know this is a result of not referencing 'lstStatus' in the code. i also have a query (qryStatus) which does not contain anything.

    My 'on-click' code for cmdStatus is

    Private Sub cmdSelect_Click()
    DoCmd.OpenQuery "qryStatus", acViewNormal, acEdit
    DoCmd.OpenReport "rptStatus", acViewReport
    DoCmd.Close acQuery, "qryStatus"



    End Sub

    I know I need to reference 'lstStatus' but am not sure where or how to do that in the code.

    I welcome any help and suggestions.

    Thank you.

  2. #2
    Nadine67 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    55
    I think I have solved my problem. I set my form code to

    Private Function GetCriteria() As String
    Dim stDocCriteria As String
    Dim VarItm As Variant
    For Each VarItm In lstStatus.ItemsSelected
    stDocCriteria = stDocCriteria & "[ImprovementID] = " & lstStatus.Column(0, VarItm) & " OR "
    Next
    If stDocCriteria <> "" Then
    stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
    Else
    stDocCriteria = "True"
    End If
    GetCriteria = stDocCriteria
    End Function

    and my cmdSelect 'on-slick' to

    Private Sub cmdSelect_Click()
    DoCmd.OpenReport "rptStatus", acPreview, , GetCriteria()
    End Sub

    Works a treat. Thank you to all who viewed my post. And thank you to Smiley for your unknowing help.

    It is a great day!

    Nadine

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

Similar Threads

  1. Replies: 2
    Last Post: 05-06-2015, 05:06 AM
  2. Replies: 15
    Last Post: 11-20-2013, 04:30 PM
  3. multi select list box
    By crowegreg in forum Forms
    Replies: 1
    Last Post: 07-28-2012, 11:52 PM
  4. Replies: 5
    Last Post: 07-26-2012, 12:59 PM
  5. Replies: 1
    Last Post: 10-22-2010, 10:11 AM

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