Solved

Creating a CSV File from a SQL Table via a MS Access Form

Posted on 2012-03-20
11
335 Views
Last Modified: 2012-08-14
I have a MS Access Form that add, updates data in a SQL Table.  On the form, I want to place a button that <WHEN PRESSED> will query the table and create a CSV file with the information in the table.  How can I do this?
0
Comment
Question by:Elroy Taulton
[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
  • 6
  • 5
11 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37742927
You first have to manually export the table and click the "Advanced" button (during the Export Wizards steps) and create an Export Specification.

Then use code like this on your button:
DoCmd.TransferText acExportDelim, "YourExportSpecificationName", "YourTableName", "C:\YourFolder\Yourfile.csv"
0
 

Author Comment

by:Elroy Taulton
ID: 37742961
Please keep in mind that we are trying to create this form for my end-user group who will not have a clue on how to manually export a table.  We are hoping to have all of this embedded in the actions of the button. (IE, it exports the data and places it in the appropriate location.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37743051
The export needs only to be done once (probably by you).
The manual Export is only needed to create the Export Specification.

After the Export Spec is created you simply run the code I posted on a button...
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:Elroy Taulton
ID: 37743167
Okay, understand.  Is there a way to format the output?  For example, I would like the export file data to be a specific order, not necessarily how they are laid out in the database table.  Also, I would like to present only returned without any additional spaces, if possible.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37743195
The data will be in the text file in the same order it is in the table.

If you want to sort the text file in a specific order, you can create a sorted query, then export the query..
<Also, I would like to present only returned without any additional spaces, if possible.>
It is not clear what this means...?


Try it first, then report back...
0
 

Author Comment

by:Elroy Taulton
ID: 37743695
Perfect.  The sorted query worked great and I now have the items in the order that I need.  The only other item is that each field is a set length and is seperated by a 'dashed line'.  My intent for this file is to use it as an import into another application so if there is any way to provide just the data without any leading or following blank spaces.  Thoughts?
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 37743745
That seems to be an issue either with the source data, or the way you set up the import Spec.
0
 

Author Comment

by:Elroy Taulton
ID: 37744789
Okay. lots of progress so far.  Looks like I was creating a formatted file so I have fixed that and am now created a file on button click.  However, the file I am creating is coming out with comma's as my delimiter instead of pipes, even though I changed it to pipes and am calling the export file specifications.  See below.  Any thoughts?

Private Sub cmdExportButton_Click()

DoCmd.TransferText acExportDelim, ZMatrixTable_Export, "ZMatrixTable Query", "C:\Work\Projects\Export\ZMatrix.txt"

End Sub

Also, is there a way to present a message back stating that the export has taken place and/or completed?
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37745657
<Any thoughts?>
Can't know without a sample database...

Sample database notes:
1. Back up your database(s).
2. Combine the front and back ends into one database file.
3. Remove any startup options, unless they are relevant to the issue.
4. Remove any records unless they are relevant to the issue.
5. Delete any objects that do not relate directly to the issue.
6. Remove any references to any "linked" files (files outside of the database, Images, OLE Files, ...etc)
7. Remove any references to any third party Active-x Controls (unless they are relevant to the issue)
8. Remove, obfuscate, encrypt, or otherwise disguise, any sensitive data.
9. Compile the code. (From the VBA code window, click: Debug-->Compile)
10. Run the compact/Repair utility.
11. Remove any Passwords and/or security.
12. If a form is involved in the issue, set the Modal and Popup properties to: No
    (Again, unless these properties are associated with the issue)
13. Post the explicit steps to replicate the issue.
14. Test the database before posting.

In other words, ...post a database that we can easily open and immediately see and/or troubleshoot the issue.
And if applicable, also include a clear graphical representation of the *Exact* results you are expecting, based on the sample data.



<Also, is there a way to present a message back stating that the export has taken place and/or completed?>
This is really getting away from the original question, ...lets get the export working first.

JeffCoachman
0
 

Author Closing Comment

by:Elroy Taulton
ID: 37745668
I have been able to successfully create the CSV file in the proper format.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37748690
;-)
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

688 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