Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Reports Throught VBA

Status
Not open for further replies.

ROUSOUG

Technical User
Jun 3, 2005
13
CY
Table Structure (called "Invoice Details"):

ID
Invoice No
Date

Other Details

I have a report (named "Invoices").
When i run the report, it desplays all invoices of the table.

What i want to do is to create some sort of code that will print Invoice No 1, close the report, then Invoice No 2, close the report, then Invoice No 3 and so on.

I need the above code for the following reasons:
1) No need to go and mannualy print each invoice (through specific invoice selection, it will be very time consuming later on when the number of invoices will increase)

2) The page numbering will be reset each time.

3) I am printing in a double side capable printer. If print all invoices through one report, (even if the page numbering is reset for each invoice) then on one paper it may print a page from one invoice on the front and on the back the next invoice (i have tried some sort of code with page breaks but it does not work because some invoices have even number of pages, some other odd).


Also, like the same way to print the invoices, can i create a .doc or .rtf file (for word) of the invoices (named after invoice number).

i know the code should like this

For x = xxx To yyy Step 1

CODE TO PRINT REPORT (PRINTER OR FILE)

Next x



Thanks
 
Hi

Suggest you use the button wizard to make a button to open a report, look at the code generated, in particular the DoCmd. line, and the linkCriteria

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
I have done this but i am not able to make the linkcriteria to work

 
Before i had the condtion set throught a query (named SelectInvoice) as follows:

invoiceid = forms!.main!.listboxinvoiceids

which worked.

I have entered the above condition in the button code as follows:

stDocName = "Test1"
DoCmd.OpenReport stDocName, acPrint, , invoiceID = Forms!Main!listboxinvoiceids

(if i can make it work for one, i can go on and use the For .. TO procedures)

the error code is "No data has been found"
 
Try:

[tt] DoCmd.OpenReport stDocName, acviewnormal, , "invoiceID = " & Forms!Main!listboxinvoiceids[/tt]

if invoiceid is a numeric field, for text

[tt]..."invoiceID = '" & Forms!Main!listboxinvoiceids & "'"[/tt]

Roy-Vidar
 
That seems to work.

Now, what is the code to save this report on the hards disk as an .rtf file?

When i preview the report, i can press the W button and the rtf file is created. how can i do this with the press of the buton?
 
Is there no condition to get specific data? (linkCriteria)

 
Nope - no link criteria - in this link thread705-1091131, I think all the methods are mentioned. Searching on keywords, you should be able to find samples too.

Roy-Vidar
 
the OutputTo may not accept criteria, but it can be combined using the OpenReport.

See below:

id = Me!listboxinvoiceids
stDocName = "Test1"
DoCmd.OpenReport stDocName, acPreview, , "[InvoiceID]=" & Me!listboxinvoiceids
DoCmd.OutputTo acOutputReport, stDocName, "Rich Text Format (*.rtf)", "c:\" & id & ".rtf", no
DoCmd.Close acReport, stDocName

One more thing to do, the From ... To ... procedure.

i have tried to do this from the command button but i cannot open the table with the source data.
i will try to create a public module.

do you have any suggestions on this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top