Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Multi select list box to generate query results

$
0
0
Hello All! In need of your assistance :) Am attempting to build a list box which allows for multiple selections and to generate a query result based on those selections. Below is the starter code which I am attempting to modify but no luck thus far.

Code:

Private Sub cmd_HMA_RUN_Click()

Private Sub cmdPreview_Click()
On Error GoTo Err_Handler

    Dim varItem As Variant
    Dim strWhere As String
    Dim strDescrip As String
    Dim lngLen As Long
    Dim strDelim As String
    Dim strDoc As String
   
    strDelim = """"
    strDoc = "HMA_CC"


    With Me.lst_HMA_PDC
        For Each varItem In .ItemsSelected
            If Not IsNull(varItem) Then

                strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim & ","
                strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
            End If
        Next
    End With
   
    lngLen = Len(strWhere) - 1
    If lngLen > 0 Then
        strWhere = "[PDCC7] IN (" & Left$(strWhere, lngLen) & ")"
        lngLen = Len(strDescrip) - 2
        If lngLen > 0 Then
            strDescrip = "PSPDAT_PSPCCHD.PDCCC7: " & Left$(strDescrip, lngLen)
        End If
    End If
   
    If CurrentProject.AllReports(strDoc).IsLoaded Then
        DoCmd.Close acReport, strDoc
    End If
   
    DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere, OpenArgs:=strDescrip

Exit_Handler:
    Exit Sub

Err_Handler:
    If Err.Number <> 2501 Then
        MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdPreview_Click"
    End If
    Resume Exit_Handler

End Sub

Here is the SQL which retrieves the necessary data from the query HMA_CC

Code:

SELECT PSPDAT_PSPCCHD.PDCCC7 AS PDC, PSPDAT_PSPCCHD.PARTC7 AS [Part Number], PSPDAT_PSPMAST.DESCPM AS [Part Name], PSPDAT_PSPCCHD.INVTC7 AS [System Qty], PSPDAT_PSPCCHD.CNT1C7 AS [Qty Count], PSPDAT_PSPCCHD.PLANC7 AS [Unit Price], PSPDAT_PSPCCHD.RCDTC7 AS [Date]
FROM PSPDAT_PSPMAST INNER JOIN (PSPDAT_PSPCCHD INNER JOIN PSPDAT_PSPCCBS ON (PSPDAT_PSPCCHD.BSEQC7 = PSPDAT_PSPCCBS.BSEQC4) AND (PSPDAT_PSPCCHD.BCTHC7 = PSPDAT_PSPCCBS.BCTHC4) AND (PSPDAT_PSPCCHD.PDCCC7 = PSPDAT_PSPCCBS.PDCCC4)) ON PSPDAT_PSPMAST.PARTPM = PSPDAT_PSPCCHD.PARTC7
WHERE (((PSPDAT_PSPCCBS.CTYPC4) In ('1','2','3','4')) AND ((PSPDAT_PSPCCHD.LTYPC7)="P") AND ((PSPDAT_PSPCCHD.VVALC7)<0))
GROUP BY PSPDAT_PSPCCHD.PDCCC7, PSPDAT_PSPCCHD.PARTC7, PSPDAT_PSPMAST.DESCPM, PSPDAT_PSPCCHD.INVTC7, PSPDAT_PSPCCHD.CNT1C7, PSPDAT_PSPCCHD.PLANC7, PSPDAT_PSPCCHD.RCDTC7, PSPDAT_PSPCCHD.VVALC7
HAVING (((PSPDAT_PSPCCHD.PDCCC7)=[Forms]![CC_SV]![HMA_PDC_CC]) AND ((PSPDAT_PSPCCHD.RCDTC7) Between [Forms]![CC_SV]![Start Date_CC] And [Forms]![CC_SV]![End Date_CC]))
ORDER BY PSPDAT_PSPCCHD.RCDTC7;

Am unsure how to modify the procedure code, state the Row Source in the list box properties, and where to indicate the number of columns in the query results (7) . Any assistance is greatly appreciated. Thanks!

Viewing all articles
Browse latest Browse all 13329

Trending Articles