Solved

Export of recordset data to ASCII (txt) file

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

773 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