[AccessD] (OT) saving as *cvs with " "

Michael R Mattys michael.mattys at adelphia.net
Thu Jan 15 17:32:29 CST 2004


This does work if you'd like to attach it to a button

0123 011-11-1123 Doe John A
0124 011-11-1124 Doe Jim B
0125 011-11-1125 Doe Jack C
0126 011-11-1126 Doe Jane D
0127 011-11-1127 Doe Jorge E
0128 011-11-1128 Doe Jean F
0129 011-11-1129 Doe Jeanine G
0130 011-11-1130 Doe Jessie H
0131 011-11-1131 Doe James I
0132 011-11-1132 Doe Jill J

Sub QuoteCommaExport()
       ' Dimension all variables.
       Dim DestFile As String
       Dim FileNum As Integer
       Dim ColumnCount As Integer
       Dim RowCount As Integer

       ' Prompt user for destination file name.
       DestFile = InputBox("Enter the destination filename" _
          & Chr(10) & "(with complete path):", "Quote-Comma Exporter")

       ' Obtain next free file handle number.
       FileNum = FreeFile()

       ' Turn error checking off.
       On Error Resume Next

       ' Attempt to open destination file for output.
       Open DestFile For Output As #FileNum

       ' If an error occurs report it and end.
       If Err <> 0 Then
          MsgBox "Cannot open filename " & DestFile
          End
       End If
       ' Turn error checking on.
       On Error GoTo 0
       ' Loop for each row in selection.
       For RowCount = 1 To Selection.Rows.Count
          ' Loop for each column in selection.
          For ColumnCount = 1 To Selection.Columns.Count
            If ColumnCount = 3 Or ColumnCount = 4 Then
             ' Write current cell's text to file with quotation marks.
                Print #FileNum, """" & Selection.Cells(RowCount,
ColumnCount).Text & """";
            Else
                Print #FileNum, Selection.Cells(RowCount, ColumnCount).Text;
            End If
             ' Check if cell is in last column.
             If ColumnCount = Selection.Columns.Count Then
                ' If so, then write a blank line.
                Print #FileNum,
             Else
                ' Otherwise, write a comma.
                Print #FileNum, ",";
             End If
          ' Start next iteration of ColumnCount loop.
          Next ColumnCount
       ' Start next iteration of RowCount loop.
       Next RowCount
       ' Close destination file.
       Close #FileNum
    End Sub


Michael R. Mattys
Try MattysMapLib for MapPoint at
www.mattysconsulting.com



----- Original Message -----
From: "Stuart McLachlan" <stuart at lexacorp.com.pg>
To: "Access Developers discussion and problem solving"
<accessd at databaseadvisors.com>
Sent: Thursday, January 15, 2004 5:15 PM
Subject: Re: [AccessD] (OT) saving as *cvs with " "


> On 15 Jan 2004 at 15:15, Oleg_123 at xuppa.com wrote:
>
> > Hey Group
> > i have to save this data (right now I have it in a spreadsheet)
> > 01003, 011-11-1123, Doe, Jane, A
> >
> > as .txt file so it would like
> >
> > 01003, 011-11-1123, "Doe", "Jane", A
> >
> >
> > and they specifically want quotes around first and last name, and ONLY
> > there. when I create *.csv file from Excel I got no quotations (I tried
> > specifically making those 2 fields as "text" and the others as "general"
> > and even "numbers", but no result) When I do it through though Acess I
get
> > all in quotations, and over there I can't play with data types. I tried
> > adding colums with " at the beginning and end of mane fields, but ehen I
> > converted that to *.csv I got tripe quotes on names, and no quotes
> > elsewhere...
> > Any suggestions ?
> >
>
> Do it yourself rather than trying to use automated routines.
> With  the data as an Access table (myData), run a function like.
>
> Function ExportData() as Long
> Dim strExport as String
> Dim rs as Recordset
> Set rs = Currentdb.Openrecordset("myData")
> Open "MyNewDataFile.csv" for Output as #1
> While  not rs.eof
> strExport = rs(0) & "," & rs(1) & ",""" & rs(2) & """,""" & rs(3) &
> """," & rs(4)
> Print #1, strExport
> rs.MoveNext
> Wend
> End Function
>
> --
> Lexacorp Ltd
> http://www.lexacorp.com.pg
> Information Technology Consultancy, Software Development,System
> Support.
>
>
>
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>



More information about the AccessD mailing list