Multiselect listbox to print seperate pdf reports - Pbaldy method (1 Viewer)

Mina Garas Daniel

Registered User.
Local time
Today, 19:02
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:02
Joined
Sep 21, 2011
Messages
14,446
I do not think that is the correct link? :unsure:

Perhaps look at the Similar threads as the bottom of this thread?
 

June7

AWF VIP
Local time
Today, 09:02
Joined
Mar 9, 2014
Messages
5,492
If the field to provide file name is in listbox second column, consider:

DoCmd.OutputTo acOutputReport, , acFormatPDF, "folderpath\" & ctl.Column(2, varItem) & ".pdf"
 

Mina Garas Daniel

Registered User.
Local time
Today, 19:02
Joined
Jul 21, 2017
Messages
66
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
 

June7

AWF VIP
Local time
Today, 09:02
Joined
Mar 9, 2014
Messages
5,492
Well, you need to replace "Folderpath\" with some real folder path for your situation.
 

Mina Garas Daniel

Registered User.
Local time
Today, 19:02
Joined
Jul 21, 2017
Messages
66
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"
 

Mina Garas Daniel

Registered User.
Local time
Today, 19:02
Joined
Jul 21, 2017
Messages
66
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
 

June7

AWF VIP
Local time
Today, 09:02
Joined
Mar 9, 2014
Messages
5,492
All I can say is code works for me.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:02
Joined
May 7, 2009
Messages
19,246
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"
 

Mina Garas Daniel

Registered User.
Local time
Today, 19:02
Joined
Jul 21, 2017
Messages
66
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:02
Joined
May 7, 2009
Messages
19,246
try the code and check if it produced the pdf.
 

Mina Garas Daniel

Registered User.
Local time
Today, 19:02
Joined
Jul 21, 2017
Messages
66
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:02
Joined
Sep 21, 2011
Messages
14,446
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

Top Bottom