Solved

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

Posted on 2015-02-12
6
132 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
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Wilder1626
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
,,,correct
;-)
0
 
LVL 11

Accepted Solution

by:
Wilder1626 earned 500 total points
Comment Utility
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
Comment Utility
Used:

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


Thank you.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now