Solved

Export file to desktop with today's date added to the end of the file name

Posted on 2015-02-12
6
146 Views
Last Modified: 2015-02-13
I'm using this code to attempt to export a file to the user's desktop WITH today's date in the file name.  Like:

Mail List 02-12-02015.csv

but it isn't working.

Here's my line of code:

    DoCmd.TransferText acExportDelim, , "qryExportMailList", strCSV & Environ("userProfile") & "\Desktop\" & "Mail List " & [txtToday] & ".csv"

which works fine until I add the   & [txtToday] &  to it.

What do I need to change the code to to make it work?
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Wilder1626
ID: 40606977
Hi, Can you try like:

Format dd/mm/yyyy
 DoCmd.TransferText acExportDelim, , "qryExportMailList", strCSV & Environ("userProfile") & "\Desktop\" & "Mail List " & format(now,"dd/mm/yyyy") & ".csv"

Open in new window


or

Format dd-mm-yyyy
 DoCmd.TransferText acExportDelim, , "qryExportMailList", strCSV & Environ("userProfile") & "\Desktop\" & "Mail List " & format(now,"dd-mm-yyyy") & ".csv"

Open in new window


or

Format ddmmyyyy
 DoCmd.TransferText acExportDelim, , "qryExportMailList", strCSV & Environ("userProfile") & "\Desktop\" & "Mail List " & format(now,"ddmmyyyy") & ".csv"

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40606997
Just a note here.

whenever you export files with the current data, you will be better to add the time as well, ...in case more than one file is for today
Also try to use the ISO date format so that the files will sort correctly in explorer.

"yyyy-mm-dd_hh-nn"
0
 
LVL 11

Expert Comment

by:Wilder1626
ID: 40607025
The time stamp will be a good option unless you want to overwrite the file if it is exported multiple times on the same day.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40607041
,,,correct
;-)
0
 
LVL 11

Accepted Solution

by:
Wilder1626 earned 500 total points
ID: 40607054
So if you want the format Month - Day - Year, requested in your first post, it would be:
 DoCmd.TransferText acExportDelim, , "qryExportMailList", strCSV & Environ("userProfile") & "\Desktop\" & "Mail List " & format(now,"mm-dd-yyyy") & ".csv"  

Open in new window


and with the time stamp added to the format Month - Day - Year:
 DoCmd.TransferText acExportDelim, , "qryExportMailList", strCSV & Environ("userProfile") & "\Desktop\" & "Mail List " & format(now,"mm-dd-yyyy_hh-nn") & ".csv"  

Open in new window

0
 

Author Closing Comment

by:SteveL13
ID: 40608009
Used:

 DoCmd.TransferText acExportDelim, , "qryExportMailList", strCSV & Environ("userProfile") & "\Desktop\" & "Mail List " & format(now,"mm-dd-yyyy_hh-nn") & ".csv"  


Thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question