Exporting a recordset to CSV

How can I export a recordset to CSV, I don't want the user to download the file, I just want the csv to be saved on the server.

The CSV should be created after the user has filled out a form this is then saved to access, but I also want to export the a csv file with one of the fields as a name, so it can be imported by another application.
ACilliersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

b0lsc0ttIT ManagerCommented:
ACilliers,

If you are saving to Access then you most likely are already using a server side language.  You should be able to create a text file using that language.  A CSV file is basically a text file with the contents formatted with commas and a line break.  Use a varialble to collect the information and format it for the CSV file.  Then use the variable to fill the text file you create.  If you would like more details then it may help to find out which language you are using.

Hope this helps.

b0lsc0tt
0
Dushan De SilvaTechnology ArchitectCommented:
remove the access rights(if cvs in linux dont give any access rights to cvs group) for that perticular folder.

BR Dushan
0
ACilliersAuthor Commented:
b0lsc0tt,

Thanks for the answer so far, I'm using ASP, and I know how to write to the access-db, but I'm unsure about writing and formating to a CSV file.

Please give some examples if you can.

ACilliers
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Dushan De SilvaTechnology ArchitectCommented:
Opps sorry, you was talking about CSV(comma seperated file) , I was talking about CVS(concurrent version controling system). Please ignore my comment.

BR Dushan
0
b0lsc0ttIT ManagerCommented:
ACilliers,

First you need to get the information together.  If the information will not be too many lines then you could do this in just one variable like below:

Dim strFileContents

strFileContents = "First,line,of,your,file" & vbcrlf
strFileContents = strFileContents & "Second,line,of,your,file" & vbcrlf
'<repeat for all of the lines>
' vbcrlf is used to insert a carriage return/line feed to give your file seperate lines

If the information will be a large number of line the you may need to create a Dictionary object.  You can visit this page (http://www.w3schools.com/asp/asp_ref_dictionary.asp) for some information on the Dictionary object if you want.  Let me know if you need more information about this.

Once you have all of the information ready for the file then you use the FileSystem object to create a text file and the TextStream object to write the information.  An example is below.  The links below the example have more information on the objects and their methods, etc.  When you specify the filename it needs to be the physical path on the server.  If you don't know the physical path then you can use Server.MapPath to get the physical path.  I will not include this in the example.  The example is below:

Dim objFS, objTS, strFile
strFile = "c:\webfolder\filename.csv"          ' Gives the filename including physical path
Set objFS = CreateObject("Scripting.FileSystemObject") ' Creates FileSystemObject
If objFS.FileExists(strFile) = False then        ' Test to make sure the file doesn't already exist
   Set objTS = objFS.CreateTextFile(strFile) ' Create the file
   objTS.Write strFileContents                      ' Fill the file with the information
   objTS.Close                                             ' Close the file and objects in the
   Set objTS = Nothing                                '     lines below
End if
Set objFS = Nothing
' If the file does exist then nothing will happen.

http://www.w3schools.com/asp/asp_ref_filesystem.asp
http://www.w3schools.com/asp/asp_ref_textstream.asp

Let me know if you have questions or need more information.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ACilliersAuthor Commented:
b0lsc0tt,

One more question:  

In the first Dim, where you define the file content, can I use a sql query string?

ACilliers
0
b0lsc0ttIT ManagerCommented:
ACilliers,

So you want information from the database in the CSV file too?  Not just the form?  An SQL query will let you get information from the database but you would still have to go through the steps of putting the information from the fields in each record in a comma seperated format and storing it for your file.  A basic example of what I think you want is below.  If you still need help, since this seems to be a different question, open a new question and post a link here.  I will be happy to continue to help.  If you feel that this is still part of your original question then you can have this question opened up again by posting to Community Support.

SQL string line
RS.Open line

Do while NOT RS.EOF
   strFileContents = strFileContents & RS("Name") & "," & RS("Address") & vbcrlf
   RS.MoveNext
Loop
RS.Close

Open your database so that it starts at the first record.  The Do While loop will go through each record from your SQL query.  The strFileContents line in my example creates gets the information for the CSV file.  There are other ways to do it but that is a good, simple example.  Before you close the loop then you need to move to the next record.

Let me know if you have other questions.  Thanks for the grade and the fun question!

b0lsc0tt
0
ACilliersAuthor Commented:
b0lsc0tt

question continued on

http://www.experts-exchange.com/Web/Q_21795425.html#16334754

Thanks for all the help so far.

ACilliers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.