Solved

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

Posted on 2004-04-06
5
929 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

710 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