Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 602
  • Last Modified:

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.
0
ACilliers
Asked:
ACilliers
  • 3
  • 3
  • 2
1 Solution
 
b0lsc0ttCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
b0lsc0ttCommented:
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
 
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
 
b0lsc0ttCommented:
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now