Solved

Export of recordset data to ASCII (txt) file

Posted on 2001-08-05
5
417 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 70

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

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…
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 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…

809 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