Technique to Export Table to Arbitrary CSV File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    Technique to Export Table to Arbitrary CSV File

    Folks,

    I'm trying to export a table to an arbitrary CSV file.

    My issue is that the output file name is under control of my application.

    Stored exports seem to require a fixed output file. Otherwise I think they'd do just fine for my immediate needs.

    Do any of you have any good suggestions or examples I can borrow from?

    Thanks,
    Oralloy
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Not exactly sure what you mean. But here is some code I use to to create a text file.

    Code:
      Dim strLabelFileName As String
       Dim fs As Object
       Dim a As Variant
    Dim myVar As Variant
    Dim i As Long
    Dim rw As Long
        Set fs = CreateObject("Scripting.FileSystemObject")
        strLabelFileName = "ShipLabel_" & Me!txtSelectedOrder & ".txt"
        strLabelFileName = "Y:\ShipLabels\" & strLabelFileName
        Set a = fs.CreateTextFile(strLabelFileName, True)
    
    'Read each line of the PREFIX text file into the list of variables
        'until the end of the file is reached
        i = 0
        rw = 1
        Do While Not (EOF(1))
            Line Input #1, myVar
            i = i + 1
            a.writeline (myVar)
        Loop
    'Close the file
        Close 1
        set fs = nothing
        set a = nothing
    Jim

    Comment

    • Oralloy
      Recognized Expert Contributor
      • Jun 2010
      • 988

      #3
      jimatqsi,

      Thanks. Not exactly what I'm trying to achieve, though.

      Basically I have a table that I'm exporting to a tool called JIRA. That tool can import CSV files, among various formats. It can't reach directly into Access databases, though. So what I am trying to do is automate (as much as possible) the export of a particular table from a fair number of existing Access databases into this common tool.

      So, in order to avoid problems with coding my own CSV exporter, I thought that using the built-in capability was the best approach.

      The problem is that it seems like the built-in CSV export requires hand execution every time, with the user being the weak link.

      I have a mechanism for automated input and output file identification. Now all I have to do is the CSV export piece.

      Comment

      • jimatqsi
        Moderator Top Contributor
        • Oct 2006
        • 1293

        #4
        You might try looking at this



        Jim

        Comment

        • Oralloy
          Recognized Expert Contributor
          • Jun 2010
          • 988

          #5
          jimatqsi,

          Thanks!

          I'll give it a try and let you know how it works out.

          Regards,
          Oralloy

          Comment

          • Oralloy
            Recognized Expert Contributor
            • Jun 2010
            • 988

            #6
            Jim,

            It looks like it'll solve my problems. Not a bad piece of code.

            Thanks!
            Oralloy

            Comment

            Working...