Solved

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

Posted on 2004-04-06
5
930 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
[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
5 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 125 total points
ID: 10771912
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
ID: 10771946
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
ID: 10771989
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
ID: 10772122
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
ID: 10772365
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

615 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