Results 1 to 9 of 9
  1. #1
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91

    Post To create a pdf from a record with a singular file name

    Hello, everyone.

    My question has two parts:

    First of all, I've been searching how to create a button that straightly generates a pdf from a report, without previewing and pressing the export button in the tool bar. Just to press a button in my form and cast the "save as" explorer. I found nothing...

    Second, I want this output default filename not to be "REPORTNAME.PDF". I want to make this filename with the data in the record. E.g.: "ID_DATE_CLIENTNAME.pdf" .



    Can anybody help me??

    Thanks anyway

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    From this site: http://www.addictivetips.com/microso...cument-format/

    Contrasting to Access 2007, in which you need to install add-ins to export database. Access 2010 offers option of exporting database in PDF (Portable Document Format) and XPS (XML paper Specification) formats. Now with Access 2010, you can export datasheet, Forms and Reports to a .pdf or .xps file, it enables you to spread information in an easy-to -distribute form that contains all formatting characteristics.
    Don't know if this will work, but try:

    Code:
    'Behind a comand button save the report as PDF file 
    Dim theFileName as string
    
    theFileName = CurrentProject.Path &"\ID_" & Date & ".pdf"
    DoCmd.OutputTo acOutputReport, "rptReportName", acFormatPDF, theFileName , False
    Change "rptReportName" to your report name.....

  3. #3
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    That's pretty good!! Thanks, ssanfu.

    But...

    Now I get a pdf of the whole report with all the records. I obviously need to filter by the Id of the record I am viewing. How can I do it? I tried with the syntax of the common report generating buttons and it didn't work.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    And another question: how do I change the default saving directory. Now the file is defaultly saved in "Documents", I want to change that.
    This site shows how to select a folder path. You would use it instead of "CurrentProject.Path"

    Now I get a pdf of the whole report with all the records. I obviously need to filter by the Id of the record I am viewing.
    I'm confused. You said you wanted to print a report as a PDF.
    Are you now saying you want to just print one record?
    Do yo mean a form instead of a report?

  5. #5
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    Quote Originally Posted by ssanfu View Post
    This site shows how to select a folder path. You would use it instead of "CurrentProject.Path"


    I'm confused. You said you wanted to print a report as a PDF.
    Are you now saying you want to just print one record?
    Do yo mean a form instead of a report?
    Yes I want to print a report, but not with all the records in the database.
    I.e: I use this:
    Code:
    DoCmd.OpenReport stDocName, acViewPreview, , "NumAnalisis = " & Nz(Me.NumAnalisis, 0)
    *NumAnalisis is the ID.
    to make a preview of only the record I am viewing.

    Imagine I wanted to make a pdf of an invoice. With this code I will get all the invoices of my database in one pdf.

  6. #6
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    No one knows how to automatically generate a pdf of a filtered-by-id report??

  7. #7
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Does this code
    Code:
    DoCmd.OpenReport stDocName, acViewPreview, , "NumAnalisis = " & Nz(Me.NumAnalisis, 0)
    open a report with just the record(s) related to "Me.NumAnalisis" or all records in the database?

  8. #8
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    Quote Originally Posted by ssanfu View Post
    Does this code
    Code:
    DoCmd.OpenReport stDocName, acViewPreview, , "NumAnalisis = " & Nz(Me.NumAnalisis, 0)
    open a report with just the record(s) related to "Me.NumAnalisis" or all records in the database?
    This code opens JUST the record I am viewing. It takes the ID from the form (e.g. Id=73) and opens the report only with the record whose id=73.

  9. #9
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    This works:

    Code:
    Me.Refresh
    Dim myPath As String
    Dim stDocName As String
    Dim theFileName As String
    
    stDocName = "Report Name"
    DoCmd.OpenReport stDocName, acPreview, , "Id = " & Nz(Me.Id, 0)
    
    myPath = "C:\..."
    theFileName = "Report Id " & Id & ".pdf"
    
    DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, theFileName, True
    But I never succeeded saving in mypath, it always get saved in Documents.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Create database from .ini file provided
    By pgb205 in forum Access
    Replies: 1
    Last Post: 03-04-2012, 01:02 AM
  2. create a button for import excel file
    By tggsun in forum Forms
    Replies: 3
    Last Post: 01-17-2012, 08:40 AM
  3. Cannot create ACCDE file
    By swilliams in forum Access
    Replies: 1
    Last Post: 06-03-2010, 03:41 PM
  4. Create a history file
    By Thomman in forum Forms
    Replies: 10
    Last Post: 04-19-2010, 08:52 AM
  5. Create Hash - Copy File to string
    By andrew_ww in forum Programming
    Replies: 0
    Last Post: 03-20-2010, 02:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums