Exporting text w/o a specification 
Author Message
 Exporting text w/o a specification

I have 7 different tables that I want to export with tabs as delimiters and
O quotes around strings.

I am using TransferText from VBA, but the default spec does not export as
described above.

How can I do this w/o having to build a specification for each table?

--

Thanks
Shawn



Sun, 29 Sep 2002 03:00:00 GMT  
 Exporting text w/o a specification
Hi Shawn,

Here is something I did a while ago.

Steve

Sub ExportDelim(strTable As String, strExportFile As String, strDeliminator As String, Optional blnHeader As Boolean)

   'strTable is the table or query name
   'strExportFile is the full path and name of file to export to
   'strDelimiinator is the field deliminator to use like Chr(9) for Tab

   Dim fld As Field
   Dim varData As Variant
   Dim rs As Recordset
   Dim intFileNum As Integer

   'set recordset on table or query
   Set rs = CurrentDb.OpenRecordset(strTable, dbOpenSnapshot)

   'get file handle and open for output
   intFileNum = FreeFile()
   Open strExportFile For Output As #intFileNum

   If blnHeader Then
      'output the header row if requested
      varData = ""
      For Each fld In rs.Fields   'traverse the fields collection
         varData = varData & fld.Name & strDeliminator
      Next

      'remove extra last deliminator
      varData = Left(varData, Len(varData) - 1)

      'write out the header row
      Print #intFileNum, varData
   End If

   'now your data
   Do While Not rs.EOF
      varData = ""
      'concatenate the data row
      For Each fld In rs.Fields
         varData = varData & fld.Value & strDeliminator
      Next

      'remove extra last deliminator
      varData = Left(varData, Len(varData) - 1)

      'write out data row
      Print #intFileNum, varData

      rs.MoveNext
   Loop

   Close #intFileNum
   Set rs = Nothing
End Sub

Quote:

> I have 7 different tables that I want to export with tabs as delimiters and
> O quotes around strings.

> I am using TransferText from VBA, but the default spec does not export as
> described above.

> How can I do this w/o having to build a specification for each table?

> --

> Thanks
> Shawn



Sun, 29 Sep 2002 03:00:00 GMT  
 Exporting text w/o a specification


Quote:
>I have 7 different tables that I want to export with tabs as
>delimiters and O quotes around strings.

>I am using TransferText from VBA, but the default spec does not
>export as described above.

>How can I do this w/o having to build a specification for each
>table?

Shawn,

Try TextExport class from http://briefcase.yahoo.com/dfurman0

--
(remove a 9 to reply by email)



Sun, 29 Sep 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Listing of Text Import/Export Specifications

2. Copy Import/Export Specifications

3. Manipulating import/export specifications in code

4. Fixed-Width Import/Export Specification File

5. Export Specifications 2.0 versus 7.0

6. composing text import specifications for use with TransferText()

7. Making a connection to an text-file with link specification

8. TransferText action & delimited text file specifications (A97)

9. Exporting a 3 decimal number to text file produces trunc 2 decimal text number

10. Aligning text in an export from Crystal to text file

11. Error "Text files specification field separator matches decimal separator or text delimator"

12. Export to csv text file

 

 
Powered by phpBB® Forum Software