![]() |
|
|
||||||||
| Site Links |
| Consulting |
| Knowledge Base |
| Training |
| Forum |
| Articles |
| Resources |
| Products |
| Cool Tools |
| Contact |
| About Us |
| Go to Page... |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
|
Urgent :How to FAST write large recordset in to a text file?
Hi Everybody
I have a large record set (about 3.5 - 4 million records with 4 fields in each record). I want to write this to a text file. The resulting text file is approximately just under 200 mB file. I tried to write record by record by string concatenating the fields and then using the Print # statement to write to a text file. Whilst it doesn't take awfully long time, it does take a little while to do so. I was wondering if there is a faster way to do the same thing. The other option that I am looking at (it works but haven't time tested for the same data set yet) is to use the GetString() function with the appropriate arguments for comma delimited columns and vbCrLf delimited rows and then store the whole record set in to a single string and then use the Print# statement to write this string to a text file. This works but I have to time test it - I am looking at doing that tomorrow at work. I am wondering if "TextStream.Write (string)" would be faster where 'string' would be the result from the GetString() function. Or is this much of a muchness in that I wouldn't be gaining a lot ether way? Any suggestions on this would be highly valued. Thanks in advance. Best regards Deepak |
|
Local Time: 01:54 AM
Local Date: 05-20-2013 Location:
|
|
|
|
#2 |
|
|
ADO would probably be faster. See: http://www.erlandsendata.no/english/index.php?t=envbadac
|
|
Local Time: 10:54 AM
Local Date: 05-19-2013 Location:
|
|
|
|
#3 |
|
|
VBA:
VBA tags courtesy of www.thecodenet.com
|
|
Local Time: 05:54 PM
Local Date: 05-19-2013 |
|
|
|
#4 |
|
|
Hi Kenneth
Sorry but the link that you suggested only works with data in an Excel spreadsheet. My data that I want to write to a text file is in a recordset and not in an Excel worksheet - it anyway won't fit in a worksheet, it contains around 4 million records Hi Snb That was exactly what I have tried and it works. I was wondering if 'Textstream.Write String' would be any faster. I am going to time test the 'TextStream.Write String' now and see if its any faster. The other option is to get is to load the recordset in an array using GetRows() function but I don't know of any function that will dump the contents of the entire array in to a text file without having to go field by field and record by record. Any further suggestions? Deepak |
|
Local Time: 01:54 AM
Local Date: 05-20-2013 Location:
|
|
|
|
#5 |
|
|
SNB is very good at coming up with short code examples.
Have you tried just saving it as a CSV file? You can copy the sheet to one workbook and save that one. ADO is far more advanced that just reading the data from Excel. It can read and write data from various ADO sources. See ConnectionStrings.com. You just have to figure out the details. I probably won't have time to dig much into it until this weekend. I would imagine that you would want to read the Excel data and then update a CSV file. To do this, you need one step to read the data and another to add it to another data set which in this case is the CSV file. It is not that much different than one MDB table to another table. The concepts are similar. Here is an example going from a CSV to Excel. Of course reading the Excel data can be an easy step. VBA:
VBA tags courtesy of www.thecodenet.com
Here is an example for getrows. VBA:
VBA tags courtesy of www.thecodenet.com
|
|
Local Time: 10:54 AM
Local Date: 05-19-2013 Location:
|
|
|
|
#6 |
|
|
Hi Kenneth
Have we got our question mixed up? My understanding is that .copyfromrecordset copies recordset content to an Excel worksheet. This is not something that I want. I want the contents of the recordset to be dumped to a text file (.txt file). Also, I had a look at the ConnectionStrings.com. I take it that I may need to use the Standard Microsoft Text ODBC drive like so :- Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=c:\txtFilesFolder\;Extensions=asc,csv,tab,txt; Here, is the Dbq the path to the output .txt file? Where do I specify the field/row delimiters? Deepak |
|
Local Time: 01:54 AM
Local Date: 05-20-2013 Location:
|
|
|
|
#7 |
|
|
The field row delimiters are by your options. I would have to look into how those can be changed via VBA.
The CopyFromRecordSet is for a Range object. I showed how to use the GetRows. Here is the saveas method. VBA:
VBA tags courtesy of www.thecodenet.com
|
|
Local Time: 10:54 AM
Local Date: 05-19-2013 Location:
|
|
|
|
#8 |
|
|
@Kenneth
alternative ? VBA:
VBA tags courtesy of www.thecodenet.com
Last edited by Aussiebear : 04-17-2012 at 04:01 PM. Reason: Corrected the spacing issue |
|
Local Time: 05:54 PM
Local Date: 05-19-2013 |
|
![]() |
| Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|


