Open a report based on values from Two List boxes value

J

Jose

I wish to open a report from the multiple values i have selected in 2
different list boxes. Name of list boxes are List24 and List 27. List24
showing the supervisor (MWC) and List27 the plants.

Please see the following code and instruct me how can i add the code
for list27 also


Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

strDelim = """"
strDoc = "Incomplete Jobs Query"
With Me.List24
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
End If
Next
End With
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[MWc] IN (" & Left$(strWhere, lngLen) & ")"
End If
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, "Maint Jobs Report"
End If
DoCmd.OpenReport "Maint Jobs Report", acViewPreview,
WhereCondition:=strWhere
 
G

Guest

Try adding the *untested* code between the asterisked lines

Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

strDelim = """"
strDoc = "Incomplete Jobs Query"

With Me.List24
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
End If
Next
End With
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[MWc] IN (" & Left$(strWhere, lngLen) & ")"
End If


'***********
Dim strWhere1 As String 'String to use as WhereCondition
With Me.List27
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere1 = strWhere1 & strDelim & .ItemData(varItem) &
strDelim & ","
End If
Next
End With
lngLen = Len(strWhere1) - 1
If lngLen > 0 Then
strWhere1 = "[Plants] IN (" & Left$(strWhere1, lngLen) & ")"
End If

If len(strWhere) > 0 then
if len(strWhere1) > 0 then
strWhere = strWhere & " AND " & strWhere1
end if
else
if len(strWhere1) > 0 then
strWhere = strWhere1
end if
end if
'**********


If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, "Maint Jobs Report"
End If
DoCmd.OpenReport "Maint Jobs Report", acViewPreview,
WhereCondition:=strWhere
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top