Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2013
    Posts
    2

    Unanswered: How to export the whole table

    Hi

    I'm new

    I've been able to export the 1st column of aN aCCESS query with this code:

    Sub ExportToText()
    Dim rst As DAO.Recordset
    Open "V:\Desktop\brookman\names.txt" For Output As #1
    Set rst = CurrentDb.OpenRecordset("SELECT [PRECID] FROM 8F_NOS_POSITIONS", dbOpenSnapshot)
    Do While Not rst.EOF
    Print #1, rst!PRECID
    rst.MoveNext
    Loop
    rst.Close
    Set rst = Nothing
    Close #1
    End Sub

    How do I expand this code, so I can export column #2, #3 etc?

    Any ideas

    Thanks in advance

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Two key lines in your code:
    Code:
    Set rst = CurrentDb.OpenRecordset("SELECT [PRECID] FROM 8F_NOS_POSITIONS", dbOpenSnapshot)
    ...
    Print #1, rst!PRECID
    To include another column
    Code:
    Set rst = CurrentDb.OpenRecordset("SELECT [PRECID], [AnotherColumn] FROM 8F_NOS_POSITIONS", dbOpenSnapshot)
    To output the other column [assuming a pipe (|) delimiter]
    Code:
    Print #1, rst!PRECID & "|" & rst!AnotherColumn
    The ampersand (&) concatenates the strings together
    George
    Home | Blog

  3. #3
    Join Date
    Oct 2013
    Posts
    2
    WHAT A COMPLETE LEGEND!!!!! WORKED 1ST TIME!

    Is this language straight VBA?

    Thanks again - beers on me!!

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by bigmc25 View Post
    Is this language straight VBA?
    It looks like VBA to me
    Quote Originally Posted by bigmc25 View Post
    Thanks again - beers on me!!
    I accept Paypal
    George
    Home | Blog

Posting Permissions

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