Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2005
    Posts
    67

    Unanswered: Adding a unique name to a text file on exporting

    Hi,

    after exporting my text file from Access, I have been asked to add a unique reference or name e.g. Filename-today's date , so that each time one is created there is a date and time attached to the filename. I have tried the following code but it is not working

    When I do this:
    Code:
        Dim Today
        
        Today = Now
    
         Shell "cmd.exe /C type D:\HeaderOutput.txt >> D:\Receipt.txt + Today"
    All i get is the normal file name - Receipt.txt as opposed to Receipt.txt-051230

    And if I do this:

    Code:
    Shell "cmd.exe /C type D:\HeaderOutput.txt >> D:\Receipt.txt +  & " - " &  Format (Today, 'yymmddhhmm')"
    I get a type mismatch error.

    Can anyone please point me in the right direction?

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Quote Originally Posted by tasha123
    Hi,

    after exporting my text file from Access, I have been asked to add a unique reference or name e.g. Filename-today's date , so that each time one is created there is a date and time attached to the filename. I have tried the following code but it is not working

    When I do this:
    Code:
        Dim Today
        
        Today = Now
    
         Shell "cmd.exe /C type D:\HeaderOutput.txt >> D:\Receipt.txt + Today"
    All i get is the normal file name - Receipt.txt as opposed to Receipt.txt-051230

    And if I do this:

    Code:
    Shell "cmd.exe /C type D:\HeaderOutput.txt >> D:\Receipt.txt +  & " - " &  Format (Today, 'yymmddhhmm')"
    I get a type mismatch error.

    Can anyone please point me in the right direction?
    You're going a little crazy on the quotes there...


    Shell "cmd.exe /C type D:\HeaderOutput.txt >> D:\Receipt.txt - " & Format (Date, 'yymmddhhmm')

    Also, you do realize you're going to break the ability of the OS to identify that file by appending the date AFTER .txt right?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Dec 2005
    Posts
    67
    LLOLLL! Ok - I'll try not to go crazy on the quotes..... with all the grief I've got from them, I was beginning to think VBA is all about quotes.

    I'll implement what you wrote and get back to you. I take it I should append the time before the '.txt' in order not to confuse the OS?

  4. #4
    Join Date
    Dec 2005
    Posts
    67
    Okay - it worked, but you were right it turned out to be an unidentified file - receipt.txt-0512.... - basically it's no longer a text file. I'll tweak it. thank you.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    wouldn't....
    Code:
    Shell "cmd.exe /C type D:\HeaderOutput.txt >> D:\Receipt" & Format (Date, 'yymmddhhmm') & ".txt"
    make more sense?

    BTW your current version is still a text file (the name doesn't change the file type), its just that you have mangled the extension so XP thinks its a different file type.

    HTH
    Last edited by healdem; 12-30-05 at 14:36.

  6. #6
    Join Date
    Dec 2005
    Posts
    67
    Yeah u're right - that was exactly what I had to do and it worked. Thanks for pushing me in the right direction.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •