Results 1 to 4 of 4
  1. #1
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168

    Export Access table data to flat file (txt file)

    I have a bit of a ? for the experts here. I have some data in Access which is in a table now (about 480 rows / 1 field containing email addresses) ... and I need to export the data to what I would call a one line comma delimited flat file.



    So the text file needs to look like this .. abcdef@email1.com,abcdef@email2.com,abcdef@email3. com ... and on and on til all my 480 email addresses are done on the one line.

    I can easily export them to 480 lines .. but that is not acceptable. I do not want to manually have to edit the txt / csv file if I do not have to as this will have to be done on a possible regular basis.

    Thanks
    - Kevin -

  2. #2
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Because .. I usually figure it out, here is my solution for anyone else that may come across this kind of thing. It may not be pretty .. but it works. I have very little experience with recordsets and writing to files as such so maybe someone else can improve upon this.

    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim oFile As Object
    Set oFile = fso.CreateTextFile("C:\*****\Current.txt")


    Dim dbsEmail As DAO.Database
    Dim rstEmail As DAO.Recordset
    Dim strSQL As String

    Set dbsEmail = CurrentDb

    strSQL = "SELECT Email FROM tblEmail;"

    Set rstEmail = dbsEmail.OpenRecordset(strSQL, dbOpenDynaset)

    'If the recordset is empty, exit.
    If rstEmail.EOF Then Exit Sub


    With rstEmail

    .MoveFirst

    Do Until .EOF

    oFile.Write rstEmail.Fields(0)
    oFile.Write Chr(44)

    .MoveNext

    Loop
    End With

    MsgBox "Completed Processing Emails", vbOKOnly, "Finished Processing Emails"

    oFile.Close
    Set fso = Nothing
    Set oFile = Nothing

    rstEmail.Close
    dbsEmail.Close

    Set rstEmail = Nothing
    Set dbsEmail = Nothing

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    An alternative could be looping code that builds string then one Write execution.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Quote Originally Posted by June7 View Post
    An alternative could be looping code that builds string then one Write execution.
    Thanks ..

    I am actually more than happy with how it is working. It takes < 1 second to run. So .. performance is not an issue and there will not be more than a minimal amount of added data in the future. It is just not how I would normally export data, but it is what was requested.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 12-12-2013, 07:22 PM
  2. Flat File Query
    By mma3824 in forum Queries
    Replies: 1
    Last Post: 10-09-2012, 08:54 AM
  3. Replies: 2
    Last Post: 08-05-2012, 06:32 PM
  4. Creating a Flat File with Signed Numeric Data Fields
    By two_smooth in forum Database Design
    Replies: 2
    Last Post: 10-27-2010, 08:31 AM
  5. Export data to .doc(x) file
    By fat drummer in forum Import/Export Data
    Replies: 0
    Last Post: 07-28-2010, 03:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums