Multiselect listbox to print seperate pdf reports - Pbaldy method

Mina Garas Daniel

Registered User.
Local time
Today, 18:46
Joined
Jul 21, 2017
Messages
66
Hi there
Greetings
My question for Pbaldy and anybody can help
I use your method to filter reports using multiselect listbox from this link

My question is how to improve this code to print pdf reports individually using multiselect listbox and give for each report name based on listbox itself

I hope u can help in this issue as usual
Thanks
 
I do not think that is the correct link? :unsure:

Perhaps look at the Similar threads as the bottom of this thread?
 
If the field to provide file name is in listbox second column, consider:

DoCmd.OutputTo acOutputReport, , acFormatPDF, "folderpath\" & ctl.Column(2, varItem) & ".pdf"
 
If the field to provide file name is in listbox second column, consider:

DoCmd.OutputTo acOutputReport, , acFormatPDF, "folderpath\" & ctl.Column(2, varItem) & ".pdf"
Dear June7
I tried that but nothing happen
no pdf reports created

Code:
Private Sub Command14_Click()
Dim strWhere As String
Dim ctl As control
Dim varItem As Variant

'make sure a selection has been made
If Me.lstFProductSearch.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 Item"
  Exit Sub
End If

'add selected values to string
Set ctl = Me.lstFProductSearch
    For Each varItem In ctl.ItemsSelected
    strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
   
'trim trailing comma
strWhere = Left(strWhere, Len(strWhere) - 1)
     
'open the report, restricted to the selected items
DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK IN(" & strWhere & ")"
DoCmd.OutputTo acOutputReport, "CST_FP", acFormatPDF, "Folderpath" & ctl.Column(2, varItem) & ".PDF"
DoCmd.Close acReport, "CST_FP"
End Sub
 
Well, you need to replace "Folderpath\" with some real folder path for your situation.
 
Well, you need to replace "Folderpath\" with some real folder path for your situation.
Code:
Dim strWhere As String
Dim ctl As control
Dim varItem As Variant

'make sure a selection has been made
If Me.lstFProductSearch.ItemsSelected.Count = 0 Then
 MsgBox "Must select at least 1 Item"
  Exit Sub
End If

'add selected values to string
Set ctl = Me.lstFProductSearch
    For Each varItem In ctl.ItemsSelected
    strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
    
'trim trailing comma
strWhere = Left(strWhere, Len(strWhere) - 1)
      
 'open the report, restricted to the selected items
DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK IN(" & strWhere & ")"
DoCmd.OutputTo acOutputReport, "CST_FP", acFormatPDF, "C:\Users\Mina.Garas\Desktop\to costing" & ctl.Column(2, varItem) & ".PDF"
DoCmd.Close acReport, "CST_FP"
 
Code:
Dim strWhere As String
Dim ctl As control
Dim varItem As Variant

'make sure a selection has been made
If Me.lstFProductSearch.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 Item"
  Exit Sub
End If

'add selected values to string
Set ctl = Me.lstFProductSearch
    For Each varItem In ctl.ItemsSelected
    strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
   
'trim trailing comma
strWhere = Left(strWhere, Len(strWhere) - 1)
     
'open the report, restricted to the selected items
DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK IN(" & strWhere & ")"
DoCmd.OutputTo acOutputReport, "CST_FP", acFormatPDF, "C:\Users\Mina.Garas\Desktop\to costing" & ctl.Column(2, varItem) & ".PDF"
DoCmd.Close acReport, "CST_FP"
I did but same result
 
what is FPPK, is it Numeric or Text?
Code:
'add selected values to string
Set ctl = Me.lstFProductSearch
For Each varItem In ctl.ItemsSelected
    'strWhere = strWhere & ctl.ItemData(varItem) & ","


    'open the report, restricted to the selected items

    ' comment this if FPPK is not numeric
    ' if FPPK is numeric
    DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK = " & ctl.ItemData(varItem)
    
    ' if FPPK is Text
    'DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK = '" & ctl.ItemData(varItem) & "'"
    
    DoCmd.OutputTo acOutputReport, "CST_FP", acFormatPDF, "C:\Users\Mina.Garas\Desktop\to costing" & ctl.Column(2, varItem) & ".PDF"
    DoCmd.Close acReport, "CST_FP"

Next varItem
  
'trim trailing comma
'strWhere = Left(strWhere, Len(strWhere) - 1)
    
'open the report, restricted to the selected items
'DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK IN(" & strWhere & ")"
'DoCmd.OutputTo acOutputReport, "CST_FP", acFormatPDF, "C:\Users\Mina.Garas\Desktop\to costing" & ctl.Column(2, varItem) & ".PDF"
'DoCmd.Close acReport, "CST_FP"
 
what is FPPK, is it Numeric or Text?
Code:
'add selected values to string
Set ctl = Me.lstFProductSearch
For Each varItem In ctl.ItemsSelected
    'strWhere = strWhere & ctl.ItemData(varItem) & ","


    'open the report, restricted to the selected items

    ' comment this if FPPK is not numeric
    ' if FPPK is numeric
    DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK = " & ctl.ItemData(varItem)
   
    ' if FPPK is Text
    'DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK = '" & ctl.ItemData(varItem) & "'"
   
    DoCmd.OutputTo acOutputReport, "CST_FP", acFormatPDF, "C:\Users\Mina.Garas\Desktop\to costing" & ctl.Column(2, varItem) & ".PDF"
    DoCmd.Close acReport, "CST_FP"

Next varItem
 
'trim trailing comma
'strWhere = Left(strWhere, Len(strWhere) - 1)
   
'open the report, restricted to the selected items
'DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK IN(" & strWhere & ")"
'DoCmd.OutputTo acOutputReport, "CST_FP", acFormatPDF, "C:\Users\Mina.Garas\Desktop\to costing" & ctl.Column(2, varItem) & ".PDF"
'DoCmd.Close acReport, "CST_FP"
Numeric
I use ms 365 if that will make difference
 
try the code and check if it produced the pdf.
 
what is FPPK, is it Numeric or Text?
Code:
'add selected values to string
Set ctl = Me.lstFProductSearch
For Each varItem In ctl.ItemsSelected
    'strWhere = strWhere & ctl.ItemData(varItem) & ","


    'open the report, restricted to the selected items

    ' comment this if FPPK is not numeric
    ' if FPPK is numeric
    DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK = " & ctl.ItemData(varItem)
 
    ' if FPPK is Text
    'DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK = '" & ctl.ItemData(varItem) & "'"
 
    DoCmd.OutputTo acOutputReport, "CST_FP", acFormatPDF, "C:\Users\Mina.Garas\Desktop\to costing" & ctl.Column(2, varItem) & ".PDF"
    DoCmd.Close acReport, "CST_FP"

Next varItem

'trim trailing comma
'strWhere = Left(strWhere, Len(strWhere) - 1)
 
'open the report, restricted to the selected items
'DoCmd.OpenReport "CST_FP", acViewPreview, , , acHidden, "FPPK IN(" & strWhere & ")"
'DoCmd.OutputTo acOutputReport, "CST_FP", acFormatPDF, "C:\Users\Mina.Garas\Desktop\to costing" & ctl.Column(2, varItem) & ".PDF"
'DoCmd.Close acReport, "CST_FP"
Dear arnel
i did your modification on code and i delete this
Code:
"C:\Users\Mina.Garas\Desktop\to costing" & ctl.Column(2, varItem) & ".PDF"
part to allow access let me select path folder and i select 2 items from listbox the problem now is each pdf file contain 2 items data not one item as i need
thanks
 
Dear arnel
i did your modification on code and i delete this
Code:
"C:\Users\Mina.Garas\Desktop\to costing" & ctl.Column(2, varItem) & ".PDF"
part to allow access let me select path folder and i select 2 items from listbox the problem now is each pdf file contain 2 items data not one item as i need
thanks
Need to show YOUR code now,as @arnelgp's code would not do that? :(
 

Users who are viewing this thread

Back
Top Bottom