Results 1 to 4 of 4
  1. #1
    oatsybob is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2012
    Posts
    28

    Formatting exported CSV file

    Hello!

    I'm working on a bit of code that queries a table for cell phone numbers and then saves the results of the query externally as a csv file to be accessed by a python script. I am able to export the data as a csv file, however when it saves the numbers are formatted like:

    xxxxxxxxxx
    xxxxxxxxxx
    xxxxxxxxxx
    xxxxxxxxxx

    when I need them to be saved like:

    xxxxxxxxxx,xxxxxxxx,xxxxxxxxx,xxxxxxxxx,xxxxxxx, etc.

    Here's my code



    Code:
    Private Sub Command13_Click()
    On Error GoTo Err_Command13_Click
    
    
    Dim db: db = "C:\Users\Michael\Desktop\Kelly_be.mdb"
    Dim exportDir: exportDir = "C:\Python27"
    Dim exportFile: exportFile = "test3.csv"
    Dim strPath As String
    
    
    strPath = "C:\Python27\test3.csv"
    
    
    If Dir(strPath) <> "" Then
        Kill (strPath)
    End If
    
    
    Dim cn: Set cn = CreateObject("ADODB.Connection")
    
    
    cn.Open _
        "Provider = Microsoft.ACE.OLEDB.12.0; " & _
        "Data Source =" & db
    
    
    cn.Execute "SELECT Kids.[Phone_Secondary] INTO [text;HDR=YES;Database=" & exportDir & _
       ";CharacterSet=65001]." & exportFile & " FROM Kids WHERE Kids.[Phone_Secondary] <> False"
    
    
    
    
    Exit_Command13_Click:
        Exit Sub
    
    
    Err_Command13_Click:
        MsgBox Err.Description
        Resume Exit_Command13_Click
        
    End Sub
    Any thoughts/guidance would be greatly appreciated! I've only ever gotten great help from this site in the past.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You need to concatenate data from multiple records into a single comma separated string?

    Review: http://allenbrowne.com/func-concat.html
    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.

  3. #3
    oatsybob is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2012
    Posts
    28
    Almost, but not exactly. My problem is less complicated. My query outputs one column in a table which I want to concatenate into a single comma separated string.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    That is what Allen's code produces, a comma-delimited string of data from multiple records. This is the only way I know to accomplish. Adapt and refine the code to suit your situation. Gist of the procedure is to open a recordset and loop through the records building string.
    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.

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

Similar Threads

  1. VBA to Format Exported Excel Data
    By rlsublime in forum Programming
    Replies: 7
    Last Post: 04-04-2012, 03:50 PM
  2. Link to txt file, but specify formatting
    By dumbledown in forum Import/Export Data
    Replies: 3
    Last Post: 03-20-2012, 05:52 AM
  3. Replies: 5
    Last Post: 02-24-2012, 11:02 AM
  4. to open Exported Excel File
    By waqas in forum Programming
    Replies: 3
    Last Post: 10-16-2011, 12:33 PM
  5. Exporting and Updating exported data
    By Singapore Sam in forum Import/Export Data
    Replies: 2
    Last Post: 12-15-2009, 09:33 AM

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