INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

save report as pdf

save report as pdf

(OP)
hi all,

I would like to save an unbound report as pdf, the problem is access is bit confused what I did was to make a command button in a form and embeded the following code in an onClick event:



Dim wsSQL As String
wsSQL = "SELECT * from tblsubject;"
Set db = CurrentDb
Set rs = db.OpenRecordset(wsSQL, dbOpenDynaset, dbSeeChanges)


Reports!rpt!subject = rs.Fields("subject").Value
rs.Close
db.Close

DoCmd.OutputTo acOutputReport, "rpt", "PDFFormat(*.pdf)", "report.pdf", True, "", 0, acExportQualityPrint


access tells me its error 2451: report name rpt doesnt exist. Any ideas please?

RE: save report as pdf

Is your report actually called "Rpt"?

RE: save report as pdf

(OP)
yes

RE: save report as pdf

your problem is here
Reports!rpt!subject = rs.Fields("subject").Value

The reports collection like the forms collection only contains the open forms/report

Since the report is not open that line of code is looking for a report in the reports collection, but there is none. Have to open it first.

RE: save report as pdf

BTW you can open it hidden if you do not want to show it.

RE: save report as pdf

(OP)
ok my point is I dont want to open the report I simply want to export it to pdf? Isnt it possible?

RE: save report as pdf

Yes you can, but as I explained that is not your problem. Your problem is that you are trying to set a value on a closed form first. That you can not do.
Reports!rpt!subject = rs.Fields("subject").Value

If you want to do that open it hidden

CODE -->

Dim wsSQL As String

wsSQL = "SELECT * from tblsubject;"
Set rs = currentdb.OpenRecordset(wsSQL, dbOpenDynaset, dbSeeChanges)
docmd.openreport "rpt",acpreview,,,achidden
Reports!rpt!subject = rs!subject
DoCmd.OutputTo acOutputReport, "rpt", "PDFFormat(*.pdf)", "report.pdf", True, "", 0, acExportQualityPrint
docmd.close acreport,"rpt"
rs.Close 

If you truly wanted it closed, you would have to open it in design view, set the property of the subject field as
Reports!rpt!subject = "= '" & rs!subject & "'"
then save the report and close the report.
Too much work, for what purpose?

RE: save report as pdf

(OP)
thanks a lot!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close