DoCmd.OutputTo - How can I add the date to my document name?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lewe22
    New Member
    • Sep 2007
    • 94

    DoCmd.OutputTo - How can I add the date to my document name?

    I am exporting snaphot files on 1st of each month. I want each file i export to automatically insert the current date.

    I have set the current date to a variable named DateTime and tried inserting this into my export string but it didn't like this... see below....

    Code:
    DoCmd.OutputTo acOutputReport, "Employer Funding Report (By Employer)", "Snapshot Format", "c:\my documents\siobhan\testsnapshot"&DateTime&".snp"
    Anyone have any other suggestions???
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    Originally posted by Lewe22
    I am exporting snaphot files on 1st of each month. I want each file i export to automatically insert the current date.

    I have set the current date to a variable named DateTime and tried inserting this into my export string but it didn't like this... see below....

    Code:
    DoCmd.OutputTo acOutputReport, "Employer Funding Report (By Employer)", "Snapshot Format", "c:\my documents\siobhan\testsnapshot"&DateTime&".snp"
    Anyone have any other suggestions???
    Try this:

    Code:
    DoCmd.OutputTo acOutputReport, "Employer Funding Report (By Employer)", acFormatSNP, "c:\my documents\siobhan\testsnapshot" & CStr(DateTime) & ".snp", False

    Comment

    • Lewe22
      New Member
      • Sep 2007
      • 94

      #3
      It doesn't like it.....am getting a VB run-time error '2024'

      "The report snapshot was not created because you don't have enough free disk space for temporary work files."

      Yet when i run the simple....

      Code:
      DoCmd.OutputTo acOutputReport, "Employer Funding Report (By Employer)", "Snapshot Format", "c:\my documents\siobhan\Employer Funding Report (By Employer).snp"
      ....it works.

      I am the administrator of mp PC and i have plenty of free disk space on my c: drive.

      I'm confused.....he lp!!

      Comment

      • puppydogbuddy
        Recognized Expert Top Contributor
        • May 2007
        • 1923

        #4
        Originally posted by Lewe22
        It doesn't like it.....am getting a VB run-time error '2024'

        "The report snapshot was not created because you don't have enough free disk space for temporary work files."

        Yet when i run the simple....

        Code:
        DoCmd.OutputTo acOutputReport, "Employer Funding Report (By Employer)", "Snapshot Format", "c:\my documents\siobhan\Employer Funding Report (By Employer).snp"
        ....it works.

        I am the administrator of mp PC and i have plenty of free disk space on my c: drive.

        I'm confused.....he lp!!
        do you have all of these directories set up on your computer:
        "c:\my documents\siobh an\testsnapshot "

        Try not having so many.....elimin ate >>>>>\testsnaps hot

        Comment

        • Stewart Ross
          Recognized Expert Moderator Specialist
          • Feb 2008
          • 2545

          #5
          Appending the date directly or as a string will add the slash characters (e.g. 12/02/08 for UK dates formatted as today). These are illegal in the filename and will cause an error.

          Use this format instead to append the date without the slash characters, year first then month then day: Format$(Date, "yymmdd")

          Stewart

          Comment

          • Lewe22
            New Member
            • Sep 2007
            • 94

            #6
            Thanks!

            As suggested the problem was in the format of the date. My fix was...

            Code:
            'LOAD CURRENT DATE TO VARIABLE - IN FORMAT dd-mm-yyyy
            Date1 = Format(Date, "dd-mm-yyyy")
                    
            'Save Report
            DoCmd.OutputTo acOutputReport, "Employer Funding Report (By Employer)", acFormatSNP, "c:\my documents\siobhan\Employer Funding Report (By Employer)" & Date1 & ".snp"

            Comment

            Working...