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)?
7 2169
Should be possible & easy. Access doesn't care what you call the file: -
DoCmd.TransferText acExportDelim, "delim", "tablename", "filename", False, "headersrequired"
-
which usually translates to
-
DoCmd.TransferText acExportDelim, "", "tablename", "filename", False, ""
-
where tablename is the name of your table and filename is the name of your file
-
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 -
Dim filename As String
-
Dim path As String
-
-
path = "full directory path to the folder where the file will be placed"
-
' remember to end the path string with a \
-
-
filename = Format(InputBox("Enter date:"), "dd/mm/yyyy")
-
filename = path & filename & ".pos"
-
-
' then use the code sammyB gave you
-
-
You can name the file anything you like (e.g. .pos) but I can't guarantee how it will behave. Try it and see.
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.
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 -
Dim filename As String
-
Dim path As String
-
-
path = "full directory path to the folder where the file will be placed"
-
' remember to end the path string with a \
-
-
filename = Format(InputBox("Enter date:"), "dd/mm/yyyy")
-
filename = path & filename & ".pos"
-
-
' then use the code sammyB gave you
-
-
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: -
Private Sub exportreport_Click()
-
On Error GoTo Err_exportreport_Click
-
-
DoCmd.TransferText acExportDelim, Query, "ExportFile", "Q:\Messengers\postage_export.csv"
-
-
Exit_exportreport_Click:
-
Exit Sub
-
-
Err_exportreport_Click:
-
MsgBox Err.Description
-
Resume Exit_exportreport_Click
-
-
End Sub
-
I basically hard coded the filename and used a query to prompt the user for a date and grab the information.
I've never tried to export a .pos file. Try exporting it as a .csv and then rename the file.
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: -
Private Sub exportreport_Click()
-
On Error GoTo Err_exportreport_Click
-
-
DoCmd.TransferText acExportDelim, Query, "ExportFile", "Q:\Messengers\postage_export.csv"
-
-
Exit_exportreport_Click:
-
Exit Sub
-
-
Err_exportreport_Click:
-
MsgBox Err.Description
-
Resume Exit_exportreport_Click
-
-
End Sub
-
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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"...
|
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...
|
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
|
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...
|
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...
|
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...
|
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"...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |