Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

Export of recordset data to ASCII (txt) file

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
DonaKeenan
Asked:
DonaKeenan
1 Solution
 
Richie_SimonettiCommented:
From within vb app or something else?
I mean, are you using Access object, application itself, other database...?
0
 
pierrecampeCommented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
DanRollinsCommented:
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
 
NetminderCommented:
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now