i'm trying create program/macro/vba in access print invoices pdf in individual files. want file names named invoice number well. i'm new access coding, although can write code in vba don't know command need things above. here's plan:
- create report invoices create 1 invoice on 1 page.
- loop through table/query (while loop eof, loop table size)
- as long there's next record, create report page it.
- only print current page , name corresponding invoice number.
- move on
i know access has tool create macro print pdf, prints , doesn't work on individual pages. that's why think should use loop. want know:
-is there better way this?
-if have way, commands need use.
-i've seen people use these codes:
dim db dao.database dim rs dao.recordset set rs = db.openrecordset("select distinct [group] [report]", dbopensnapshot) can explain these mean?
also, @ work can't install programs. use access 2010
for such problem, work filtering capabilities of report... - build query prepare data need invoices (in case invoice) - build report print invoices, based on query invoice - use "where condition" when opening report filter on 1 invoice example, following code .pdf per invoice, name of pdf id of invoice. used invoice_id unique id of invoice
option compare database option explicit private sub startinvoice_click() dim myrs recordset dim mypdf, mystmt string ' open record set list of invoice number print mystmt = "select distinct invoice_id invoice" set myrs = currentdb.openrecordset(mystmt) ' each invoice, print in .pdf until myrs.eof ' set output path of pdf file invoice mypdf = "c:\temp\invoice_" & format(myrs.fields("invoice_id"), "000000") & ".pdf" ' open report proper condition docmd.openreport "invoice", acviewpreview, , "invoice_id = " & myrs.fields("invoice_id").value ' generate output in pdf docmd.outputto objecttype:=acoutputreport, objectname:="invoice", outputformat:=acformatpdf, outputfile:=mypdf, outputquality:=acexportqualityprint docmd.close ' close report myrs.movenext ' read next loop ' cleanup myrs.close set myrs = nothing end sub hope helps
Comments
Post a Comment