Results 1 to 13 of 13

Thread: [RESOLVED]Creating a file with today's date

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    14

    Resolved [RESOLVED]Creating a file with today's date

    Is creating a file with today's date as a name possible? If it is, how plz?

    Thanks.
    Last edited by OOGABOOGA; May 11th, 2007 at 09:41 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Creating a file with today's date

    Code:
    Open "d:\oogabooga" & Format(Now,"mm/dd/yyyy") & ".txt" For Append As #1

  3. #3
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Creating a file with today's date

    Hack, is the ".txt" file name extension mandatory?. Just curious.
    Doctor Ed

  4. #4
    Addicted Member sigid's Avatar
    Join Date
    May 2006
    Location
    Massachusetts, USA
    Posts
    182

    Re: Creating a file with today's date

    ...and if you are planning to create several files on the same date, you may want to add the time to the file name.
    Suggest you might consider something like:
    strT = Format$(Now,"yyyy-mm-dd-hh-nn-ss")
    strFileName = "D:\" & strT & "-OOGABOOGA.TXT"
    Note they will also be sortable in Windows Explorer using this type of format, based on date and time created.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Creating a file with today's date

    No, the file extension isn't mandatory, but you should include one.

    Are you creating text files?

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    14

    Re: Creating a file with today's date

    I just get "Path not found" when i try either of youre ideas

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Creating a file with today's date

    How can you get a "path not found" on a file that doesn't exist yet?

    What is the exact code that you are running?

  8. #8
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Creating a file with today's date

    An alternative to Hack's solution:
    Code:
    Dim MyFile As String
    Private Sub Form_Load()
    MyFile = Date$
    Open MyFile For Binary As #1
    Close
    MsgBox "My new file is named " & MyFile ' Returns 3-11-2007
    End Sub
    Note that when you run this after midnight tonight, a new file will be created. Until then, you can work with the same file name, which on the second excecution and thereafter, it is no longer "new".
    Doctor Ed

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    14

    Re: Creating a file with today's date

    I've tried
    Code:
    Open "F:\New Folder" & Format(Now, "mm/dd/yyyy") & ".txt" For Append As #1
    and
    Code:
    Dim monthfile As String
    monthfile = "C:\" & Format(Now, "mm/dd/yyyy") & ".txt"
    Open monthfile For Append As #20
    Both of them give the same error.

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Creating a file with today's date

    CodeDoc has pointed out a flaw in my example. Windows does not like "/" in file names so you would need to format it as mm-dd-yyyy

  11. #11

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    14

    Re: Creating a file with today's date

    Yayyy works, thank.

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Creating a file with today's date

    Sorry for the confusion. I am just sooooooooooo used to Formatting dates with the / character that I just typed that out without thinking about how it was going to be used.

    Do you have any other questions?

    If not, you could help us out by pulling down the Thread Tools menu and click the Mark Thread Resolved menu item. That will let everyone know that you have your answer.

    Thank you.

  13. #13

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    14

    Re: [RESOLVED]Creating a file with today's date

    Nope no more questions just yet.

    And done

Posting Permissions

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



Click Here to Expand Forum to Full Width