Solved

Export From Access Select Query to tab delimited Text file without quotation marks around fields

Posted on 2004-04-06
5
918 Views
Last Modified: 2013-12-25
Hello Experts,

I am using VB6 and Access 2000 with ADO.

I am queries to select data from an Access database and then create a tab delimited text file with this data.

It is working but I have no idea how to do this without the quotation marks around each field, other than using the getString method with recordsets which I would prefer not to do as I have a huge amount of records to write to these files and I also need to be able to update the textfile based on queries.

This is the code I am currently using,

strSQL = "SELECT cKH_NR AS KH_NR, cKalk_Zeitraum AS Kalc_Zeitraum, cEpiNum AS Fall_Nr " & _
" INTO [Text;Database=C:\Clino\;" & _
" HDR=YES;FMT=TabDelimited].[TEST.txt] " & _
" FROM " & gstrDataPath & "\clinotelexport.Clinotelexport  WHERE cKStGr = 'OP' "

db.execute(strSQL)

which is producing
"KH_NR"      "Kalc_Zeitraum"      "Fall_Nr"
"260590402"      "2002"      "1000070007"
"260590402"      "2002"      "1000070007"

what I need is
KH_NR      Kalc_Zeitraum      Fall_Nr
260590402                      2002      1000070007
260590402                      2002      1000070007

any help would really be appreciated

Cheers
0
Comment
Question by:Joym123
5 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 125 total points
Comment Utility
Export to a text file with the GetString method
The GetString method of the Recordset object returns a formatted string that contains all the values in each field and each row in the recordset, with your choice of column and row delimited. You can therefore use it to quickly and easily export the recordset to a comma-delimited text file, for later importing it into another database:

Dim rs As New ADODB.Recordset

' open the recordset (use a valid connection string for your system)
rs.Open "authors", "DSN=pubs", , , adCmdTable
Open "c:\authors.dat" For Output As #1
' the last argument tells how Null should be rendered
Print #1, rs.GetString(, , ",", vbCrLf, "");
Close #1

The problem with this simplicistic approach, however, is that very large Recordset - with thousands of rows or more - generate very large strings, which impact on performance. A better way to create the file is to split the Recordset in smaller blocks of, say, one hundred rows:

Dim rs As New ADODB.Recordset

' open the recordset (use a valid connection string for your system)
rs.Open "authors", "DSN=pubs", , , adCmdTable
Open "c:\authors.dat" For Output As #1
Do Until rs.EOF
    Print #1, rs.GetString(, 100, ",", vbCrLf, "");
Loop
Close #1

Note that you can export to a tab-delimited text file simply by modifying the 3rd argument of the GetString method:

    Print #1, rs.GetString(, 100, vbTab, vbCrLf, "");

0
 

Author Comment

by:Joym123
Comment Utility
Thanks for the reply ,

But as I stated in my original post, I am looking for a way of doing this directly to a text file not through recordsets using GetString.  I have alot (upwards of 800 000 ) records and therefore performance is an issue and I am trying to find the most direct efficient way.


0
 
LVL 18

Accepted Solution

by:
Sethi earned 125 total points
Comment Utility
I have been working on a few projects lately that involve import and expoerts between Excel, Access and textfiles. This is what I have found:
1. You can not rely on any in built methods of Export from Access and they are not consistent with their output.
2. It is best to use a recordset and loop through each record and write or read that record in or from a text file.

So the best method that I discovered was looping through a recordset. This wont leave a quotation mark.
0
 

Author Comment

by:Joym123
Comment Utility
Sethi,

Thanks for the input.  I will leave the question open until tomorrow and see if anyone has any other suggestions.  If not I will split the points between you and Dhaest.

It looks like I will have to do with getString anyway, as I am also using stored queries at some points and when I refer to these in the execute sql statement I don't even get a tab delimited output.  So I guess you are right about the output being inconsistent.

Cheers

joy
0
 
LVL 27

Expert Comment

by:Dabas
Comment Utility
Hi Joym123,

I agree with Sethi.
A loop like he proposes will probably take 5 lines of code, and the performance will not be much slower.
You have total control of what is happening, and if in the future you want any further changes, it will be easier to implement.

Dabas
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now