save to PDF based on multi select list box (1 Viewer)

Andyrew21

New member
Local time
Today, 15:35
Joined
Aug 4, 2017
Messages
4
hi,

i have got my save report to PDF working perfectly currently but it only works on a one by one process.

Code:
Private Sub SavePDFbttn_Click()

Dim MyPath
Dim PONumber
Dim Warehouse
Dim SBV
Dim Thefilename As String

DoCmd.OpenReport "Purchase_Order", acViewPreview

MyPath = Me.SaveLoactionTXT & "\"
PONumber = "PO Number " & Screen.ActiveReport.Txtponum & ".pdf"
Warehouse = Screen.ActiveReport.txtWarehouse & " "
SBV = Screen.ActiveReport.txtSBvendor & " "

Thefilename = MyPath & SBV & Warehouse & PONumber

DoCmd.OutputTo acOutputReport, Purchase_Order, acFormatPDF, Thefilename

DoCmd.Close acReport, "Purchase_Order"

End Sub

this is taking a PO number from a list box in a sub query and creating the report for this PO number.

as i said it works perfectly currently but i would like to amend it so rather than just taking one PO number is takes a selection.

i am guess i have to loop this somehow but i am at a loss as to how right now

any help would be great

thanks
 

Ranman256

Well-known member
Local time
Today, 18:35
Joined
Apr 9, 2015
Messages
4,337
put all your target POs in a query, this query shows in a list box.
the code will cycle thru the list box, printing reports as it goes.
The query in the report,looks at the list box to get the PO.
all data needed is in the listbox with 3 columns

Code:
sub btnPrintRpts_click()
dim itm
dim i as integer

for i = 0 to lstBox.listcount -1
    itm = lstBox.itemdata(i)    'get next item in listbox
    lstBox = itm		'set the listbox to this item

              'get vitals off the listbox
	MyPath = Me.SaveLoactionTXT & "\"
	PONumber = lstBox.column(0)
	Warehouse = lstBox.column(1)
	SBV = lstBox.column(2)

   Thefilename = MyPath & SBV & Warehouse & PONumber
   DoCmd.OutputTo acOutputReport, Purchase_Order, acFormatPDF, Thefilename
next

end sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:35
Joined
May 7, 2009
Messages
19,246
will need to revised the RecordSource of your report.
possibly, add a Tempvars as your Criteria, say [PO Number]=[Tempvars]![PoRpt].

Example:
Code:
Private Sub SavePDFbttn_Click()
Dim varItem as Variant
If IsNull(Tempvars!PoRpt) Then
	Tempvars.Add "PoRpt", "a"
End If
For Each varItem In Me.yourListBox.ItemsSelected
	Tempvars!PoRpt=Me.yourListBox.ItemData(v)
	DoCmd.OpenReport "Purchase_Order", acPreview
	DoCmd.Output acOutPutReport, "Purchase_Order", .......
	DoCmd.Close acReport, "Purchase_Order"
Next
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:35
Joined
May 7, 2009
Messages
19,246
if you don't want to change the underlying Query of your report,
then you can also do this

Example:
Code:
Private Sub SavePDFbttn_Click()
Me.yourListBox.SetFocus
For Each varItem In Me.yourListBox.ItemsSelected
	Me.yourListBox.ListIndex = varItem
	DoCmd.OpenReport "Purchase_Order", acPreview
	DoCmd.Output acOutPutReport, "Purchase_Order", .......
	DoCmd.Close acReport, "Purchase_Order"
Next
End Sub
 

Users who are viewing this thread

Top Bottom