Export Report as PDF & Save with Today's Date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Babea
    New Member
    • Mar 2013
    • 7

    Export Report as PDF & Save with Today's Date

    I am trying to create a macro to save the PDF each day. The following is what I have so far. The Output File code is the one that is probably causing me problems.

    Thanks!

    Code:
    Access 2010
    ExportWithFormatting
    Object Type:Report
    Object Name:R_Daily_Log
    OutputFile: "R:\PRIVATE\OEA\Daily_Media_Logs\"&"Media_Log-"& (Format(Date(),"yymmdd")&".pdf"
    Last edited by zmbd; Mar 28 '13, 06:32 PM. Reason: [Z{Placed the code tags...}]
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    Do you get an error message with this or does it just not produce the results that you want? If you get an error message, please provide the exact wording.

    While this shouldn't matter, you have split up your OutputFile string more than you need to. You should be able to use
    Code:
    "R:\PRIVATE\OEA\Daily_Media_Logs\Media_Log-" & Format(Date(), "yymmdd") & ".pdf"
    In writing that out, I just noticed that you have one too many (. Try removing the one before the Format, or just copy what I have.

    Comment

    • Babea
      New Member
      • Mar 2013
      • 7

      #3
      First - Thanks for your help. I tried your code with and without the extra "(" and it paste the following file in the right folder "Media_Log-". However, it overwrites it every time I run it. The code added a #1 when I first pasted it at the beginning, and it did not work until I deleted it.

      Error message = MS Access can't save the output data to the file that you've selected.
      *File may be open - not because it is going to be new each day
      *Using a template - not
      *Disk space - should not be an issue
      *Make sure the file exists on the path specified. ??New??
      *Check to make sure you have permission to write to the folder. This should not be a problem.

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        I have never done this via Macro, so this is mostly guessing. Please verify that the folder R:\PRIVATE\OEA\ Daily_Media_Log s does exist. If if does, then right just right clicking in the folder, hover over New, and select Text document. As long as it allows you to create the file, then you have permissions to create new files.

        If none of this works, I would have to recommend using VBA as most of us at Bytes don't have much experience with Macros and use VBA almost exclusively. The error messages also tend to be a little more helpful.

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          Babea:
          Macro language will have very little support in this forum as most of us use VBA.

          It will be helpfull to see your entire macro... HOPFULLY, you are using Access 2010 (please)
          If so,
          Please open the macro in design mode.
          Click somewhere within the code... do Not Double Click!
          Press <ctr><a> to select everything within the macro.
          Press <ctrl><c> to copy
          Open this thread.
          In the replay box, Click on the [CODE/] button in the tool bar.
          Place the cursor between the [CODE] [/CODE] tags
          press <ctrl><v>

          You should get look something like>>>

          Code:
          <?xml version="1.0" encoding="UTF-16" standalone="no"?>
          <UserInterfaceMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application"><UserInterfaceMacro MinimumClientDesignVersion="14.0.0000.0000"><Statements><ConditionalBlock><If><Condition>[currentproject].[istrusted]</Condition><Statements><Action Name="Beep"/> (...omitted the remaining)

          - Now we can see your macro. :)

          Comment

          • Babea
            New Member
            • Mar 2013
            • 7

            #6
            Code:
            Name="ExportWithFormatting"><Argument Name="ObjectType">Report</Argument><Argument Name="ObjectName">R_Daily_log</Argument><Argument Name="OutputFormat">PDFFormat(*.pdf)</Argument><Argument Name="OutputFile">"R:\PRIVATE\OEA\Daily_Media_Logs\Media_Log- &amp; (Format(Date(), "yyyymmdd")) &amp;.pdf</Argument><Argument Name="AutoStart">Yes</Argument></Action></Statements></UserInterfaceMacro></UserInterfaceMacros>
            Last edited by Rabbit; Mar 28 '13, 07:59 PM. Reason: Please use code tags when posting code.

            Comment

            • Babea
              New Member
              • Mar 2013
              • 7

              #7
              I have been able to get a file saved in the file, but it will not add the date. It also replaces itself each time I run it. I need it to place the date and retain it.

              Thanks!

              Comment

              • Seth Schrock
                Recognized Expert Specialist
                • Dec 2010
                • 2965

                #8
                You didn't put it in Code tags as requested. It looks like you are missing an ending double quote in the OutputFile line. Make sure that you have quotes around everything correctly.

                Could you provide the name that it is saving the file as so that we can see what it is producing?

                Comment

                • Babea
                  New Member
                  • Mar 2013
                  • 7

                  #9
                  File name: Media_Log-&Format(Date(), mmddyyyy)&

                  It will save a variety of names, but it does not like quotes before Format or around the .pdf.

                  Comment

                  • Babea
                    New Member
                    • Mar 2013
                    • 7

                    #10
                    I added the additional quotes at the end, and it gave me the following file name:Media_Log- & (Format(Date(),

                    It also took away the PDF file format.

                    Originally posted by Seth Schrock
                    You didn't put it in Code tags as requested. It looks like you are missing an ending double quote in the OutputFile line. Make sure that you have quotes around everything correctly.

                    Could you provide the name that it is saving the file as so that we can see what it is producing?

                    Comment

                    • Seth Schrock
                      Recognized Expert Specialist
                      • Dec 2010
                      • 2965

                      #11
                      You don't want the quotes to end after the & Format(Date(), "mmddyy"). They need to end right before that. Everything in the file path before that needs to be inside a set of double quotes. You would also need quotes around the .pdf, unless you don't have to specify the file extension when using a Macro, but that would surprise me. Not sure why it doesn't like it. Try copying what I have in post #2 again and tell us what the file name turns out as.

                      Comment

                      • Babea
                        New Member
                        • Mar 2013
                        • 7

                        #12
                        When using the ExportWithForma ting macro, it has me declare the type of document that I want to export. When I add the quotes around the PDF, it creates it a RTF document, and when I take the quotes away it creates a PDF.

                        Comment

                        Working...