save to PDF based on multi select list box

Andyrew21

New member
Local time
, 17:05
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
 
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
 
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
 
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

Back
Top Bottom