CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Export Data

  1. #1
    Join Date
    Apr 2001
    Posts
    29

    Export Data

    I need to export data from an access database as a *.csv. Any ideas?? Is this possable?


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Export Data

    For example you want to export Your table to the temp.csv file with "|" as delimeter

    create a recordset from your table and then

    rs.movefirst
    do while not rs.eof
    Open "c:\temp.csv" For Output As #1 'to write to
    Print #1, rs!Field(1).Value & "|" & rs!Field(2).Value & ...etc
    Close #1
    rs.movenext
    Loop

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Feb 2001
    Location
    PA
    Posts
    163

    Re: Export Data

    The following code will create a .csv file from an Access 2000 table:
    Note this will put double quotes around each field in the .csv file. If you do not want the double quotes then use the export wizard to create a specification by changing the text qualifier to none. Put the specification name just before the table name in the code below.

    Dim appAccess as new Access.Application
    '***********************************************************************
    '************* Open Access database and transfer file to DB ************
    'Must select Access 8 Object Library for Access 97 &
    'Access 9 Library for Access 2000 in Project|References
    'Open Database DB Path Exclusive
    appAccess.OpenCurrentDatabase "Path\Some..MDB", true

    ' Transfer text file to database
    appAccess.DoCmd.TransferText acExportDelim,"[Specification Name if required]" , "Tablename", "Path\somefile.csv", 1

    ' Close
    appAccess.CloseCurrentDatabase

    ' set object to nothing
    set appAccess = nothing





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured