473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

export .csv with filename dependent on date

7
I am not sure if this is even possible. All of my research has me leaning towards "no", but maybe I missed something. I am trying to export and save a .csv file whose name depends on the date entered. That is, I have a Microsoft Access program with a button that exports a .csv file. The button asks for a date and then gathers all of the information inputed on that day and exports it. Is there a way to code it such that it takes the date given by the user (ex. 9/1) and turns that into the filename (ex. 070901.csv)?

Also, would it be possible to have the file be csv without actually naming it .csv (i.e. .pos)?
Sep 5 '07 #1
7 2169
SammyB
807 Expert 512MB
Should be possible & easy. Access doesn't care what you call the file:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferText acExportDelim, "delim", "tablename", "filename", False, "headersrequired"
  2. which usually translates to
  3. DoCmd.TransferText acExportDelim, "", "tablename", "filename", False, ""
  4. where tablename is the name of your table and filename is the name of your file
  5.  
Sep 5 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
I am not sure if this is even possible. All of my research has me leaning towards "no", but maybe I missed something. I am trying to export and save a .csv file whose name depends on the date entered. That is, I have a Microsoft Access program with a button that exports a .csv file. The button asks for a date and then gathers all of the information inputed on that day and exports it. Is there a way to code it such that it takes the date given by the user (ex. 9/1) and turns that into the filename (ex. 070901.csv)?

Also, would it be possible to have the file be csv without actually naming it .csv (i.e. .pos)?
All you have to do is create a variable to hold the filename. You don't say how you are getting it so I'm presuming an input box

Expand|Select|Wrap|Line Numbers
  1. Dim filename As String
  2. Dim path As String
  3.  
  4.     path = "full directory path to the folder where the file will be placed" 
  5.     ' remember to end the path string with a \
  6.  
  7.     filename = Format(InputBox("Enter date:"), "dd/mm/yyyy")
  8.     filename = path & filename & ".pos"
  9.  
  10.     ' then use the code sammyB gave you
  11.  
  12.  
You can name the file anything you like (e.g. .pos) but I can't guarantee how it will behave. Try it and see.
Sep 5 '07 #3
I am not sure if this is even possible. All of my research has me leaning towards "no", but maybe I missed something. I am trying to export and save a .csv file whose name depends on the date entered. That is, I have a Microsoft Access program with a button that exports a .csv file. The button asks for a date and then gathers all of the information inputed on that day and exports it. Is there a way to code it such that it takes the date given by the user (ex. 9/1) and turns that into the filename (ex. 070901.csv)?

Also, would it be possible to have the file be csv without actually naming it .csv (i.e. .pos)?
Most .csv files ive seen are simply comma separated values (csv). In other words, you can open them with any text editor.
A good test is if you created a .csv, Excel defaults to opening it. If the format is bad, Excel will complain.
Not sure if this answers your question or not.
Sep 5 '07 #4
kchang
7
All you have to do is create a variable to hold the filename. You don't say how you are getting it so I'm presuming an input box

Expand|Select|Wrap|Line Numbers
  1. Dim filename As String
  2. Dim path As String
  3.  
  4.     path = "full directory path to the folder where the file will be placed" 
  5.     ' remember to end the path string with a \
  6.  
  7.     filename = Format(InputBox("Enter date:"), "dd/mm/yyyy")
  8.     filename = path & filename & ".pos"
  9.  
  10.     ' then use the code sammyB gave you
  11.  
  12.  
You can name the file anything you like (e.g. .pos) but I can't guarantee how it will behave. Try it and see.
Thanks, your suggestion worked for the most part. Access doesn't seem to like the file format I'm giving it (.pos), saying that it "Cannot update. Database or object is read-only." It works if I name it something conventional (i.e. .csv). Any thoughts?

As for how I got the information/filename here is my original code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub exportreport_Click()
  2. On Error GoTo Err_exportreport_Click
  3.  
  4.     DoCmd.TransferText acExportDelim, Query, "ExportFile", "Q:\Messengers\postage_export.csv"
  5.  
  6. Exit_exportreport_Click:
  7.     Exit Sub
  8.  
  9. Err_exportreport_Click:
  10.     MsgBox Err.Description
  11.     Resume Exit_exportreport_Click
  12.  
  13. End Sub
  14.  
I basically hard coded the filename and used a query to prompt the user for a date and grab the information.
Sep 6 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
I've never tried to export a .pos file. Try exporting it as a .csv and then rename the file.
Sep 6 '07 #6
SammyB
807 Expert 512MB
Thanks, your suggestion worked for the most part. Access doesn't seem to like the file format I'm giving it (.pos), saying that it "Cannot update. Database or object is read-only." It works if I name it something conventional (i.e. .csv). Any thoughts?

As for how I got the information/filename here is my original code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub exportreport_Click()
  2. On Error GoTo Err_exportreport_Click
  3.  
  4. DoCmd.TransferText acExportDelim, Query, "ExportFile", "Q:\Messengers\postage_export.csv"
  5.  
  6. Exit_exportreport_Click:
  7. Exit Sub
  8.  
  9. Err_exportreport_Click:
  10. MsgBox Err.Description
  11. Resume Exit_exportreport_Click
  12.  
  13. End Sub
  14.  
I basically hard coded the filename and used a query to prompt the user for a date and grab the information.
I think your parameters are wrong for line 4. See my post above. Did you open the file in the editor to see if it looked OK?
Sep 6 '07 #7
kchang
7
I think your parameters are wrong for line 4. See my post above. Did you open the file in the editor to see if it looked OK?
That's how I used to export the file. For all intents and purposes it seemed to work; however, the users want the file to be named based on the date. Your code combined with what mmccarthy gave me does the job.

I've never tried to export a .pos file. Try exporting it as a .csv and then rename the file.
Yeah, that's what I ended up doing.
Sep 6 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: DarkSpy | last post by:
many c++ compilers including "gcc" have not implemented the "export" keyword, but the comeau compilers made it (just i knew). i want to know about: is it too difficult to implement "export"...
0
by: Shawn Mehaffie | last post by:
I have the following class that I've wirtten to take a Dataset and automatically export it to either XML, ASCII or Tab delimited file. The reason I wrote it they way I did was that I don't want to...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
3
by: Jorge Cecílio | last post by:
Hi! I would like to export some MS-Access reports output to pdf. However, the only possibility offered by Access (afaik) for me to export formatted output is snp (snapshot) (I use MS-Office...
3
by: mattdaddym | last post by:
Hi all, I have been using the following code to export my datagrids to excel for quite some time. Very simple and very effective. <code> Sub btnExcelExport_Click ( s As Object, e As...
0
by: Shawn Mehaffie | last post by:
I have the following class that I've wirtten to take a Dataset and automatically export it to either XML, ASCII or Tab delimited file. The reason I wrote it they way I did was that I don't want to...
13
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
6
by: micksitup | last post by:
Hi all, I wish to find out how to export data to excel from access as follows: Select date range (which i understand how to do) The data from an entire table is sent to excel the filename...
2
by: farukcse | last post by:
Dear Sir, I have a PHP script that export CSV with arabic text, for example I download the CSV on the website then save to desktop of my computer and Open it on NOTEPAD... that works fine I could...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.