Solved

Export of recordset data to ASCII (txt) file

Posted on 2001-08-05
5
412 Views
Last Modified: 2006-11-17
Hi there,

How can I export the contents of a recordset to an ASCII (txt) semi-column delimited file? The recordset fields are also used to populate a DBGrig control.

Thank you in advance!

Dona
0
Comment
Question by:DonaKeenan
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6353540
From within vb app or something else?
I mean, are you using Access object, application itself, other database...?
0
 
LVL 6

Accepted Solution

by:
pierrecampe earned 50 total points
ID: 6354195
since you did not specify it i assume an access db and DAO

Private Sub Command1_Click()
    Dim db As DAO.Database
    Set db = OpenDatabase("C:\db1.mdb")
    db.Execute "SELECT * INTO [Text;DATABASE=C:\].[Table1.csv] FROM Table1;"
    db.Close    
    Set db = Nothing
End Sub

this will create table1.csv
it will also create a schema.ini file that describes the layout of table1.csv
if your list separator(in windows settings) is a semicolon then there will be an entry in schema.ini that reads:Format=Delimited(;)
if that entry is something else (you have an other list separator) than just replace that something else with a semicolon and the next time you run that code table1.csv will be semicolon separated
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 6354340
You can use this:

Public Sub CopyRsToCSV(ByVal prstData As ADODB.Recordset, Optional ByVal pstrFileName As String)
Dim intFileNumber As Integer
Dim lngLoop As Long
Dim strX As String

    If Len(Trim$(pstrFileName)) = 0 Then pstrFileName = App.Path & "\zzRst.csv"
   
    'Open data file data to file
    intFileNumber = FreeFile   ' Get unused file
    Open pstrFileName For Output As #intFileNumber
    'Write data to file
    With prstData
        strX = ""
        For lngLoop = 0 To .Fields.Count - 1
            strX = strX & .Fields(lngLoop).Name & ", "
        Next lngLoop
        Print #intFileNumber, strX
        If .RecordCount > 0 Then .MoveFirst
        Do Until .EOF
            strX = ""
            For lngLoop = 0 To .Fields.Count - 1
                strX = strX & .Fields(lngLoop).Value & ", "
            Next lngLoop
            Print #intFileNumber, strX
            .MoveNext
        Loop
    End With
    'Close
    Close #intFileNumber
End Sub
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7198493
Hi DonaKeenan@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept pierrecampe's comment(s) as an answer.

DonaKeenan@devx, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7213240
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 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

19 Experts available now in Live!

Get 1:1 Help Now