Exporting with TransferText and schema.ini

I am sure this problem has been raised before.  I am trying to do an export of a table using transferText.  I need it to be tab delimited so I am creating a schema.ini just before the transfertext call.  

DoCmd.TransferText acExportFixed, , "tempSubTestScoresExp", fileName, True, "", 437

I get an error when I leave out a spec argument and also when I put the path and name of schema.ini....what gives?  I read that this is a known problem, but can't understand any of the workarounds given.   Can someone help me out???
Who is Participating?
moduloConnect With a Mentor Commented:
PAQed with points refunded (100)

Community Support Moderator
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
acExportFixed is a fixed-width export, as opposed to acExportDelim which as delimeted.

You'll need to create and save an import spec that states tab delimeted, then refer to it in your TransferText line.

DoCmd.TransferText acExportDelim , {MyImportSpecName}, "tempSubTestScoresExp", fileName, True, "", 437

Hope this helps.
I use the specification.

Do a "dummy" import of your data using the wizard.  Then on the last screen before you hit "Finish" go Advanced, then "Save" or Save As r something.

GIve it a name (Ill use mySpec for this example) then you can use

DoCmd.TransferText acExportFixed, "mySpec", "tempSubTestScoresExp", fileName, True

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

What's this 437 all about????  (maybe A97 is different???)

requisiteSystemAuthor Commented:
I'm not interested in using specs because the export will have different field names each time its run.   This is why I am creating the schema.ini on the fly from the table and then exporting it.   Sorry I meant tab-delimited.  Really looking for a solution that involves the schema.ini.  Thanks.
requisiteSystemAuthor Commented:
or is it possible to use vba to write directly to the system tables that have the spec info, in order to create a spec on the fly???
requisiteSystemAuthor Commented:
I am using the function that is available on msdn to create a schema.ini.
here it is:

Private Function CreateSchemaFile(bIncFldNames As Boolean, _
                                       sPath As String, _
                                       sSectionName As String, _
                                       sTblQryName As String) As Boolean
         Dim Msg As String ' For error handling.
         On Local Error GoTo CreateSchemaFile_Err
         Dim ws As Workspace, db As Database
         Dim tblDef As TableDef, fldDef As field
         Dim i As Integer, Handle As Integer
         Dim fldName As String, fldDataInfo As String
         ' -----------------------------------------------
         ' Set DAO objects.
         ' -----------------------------------------------
         Set db = CurrentDb()
         ' -----------------------------------------------
         ' Open schema file for append.
         ' -----------------------------------------------
         Handle = FreeFile
         Open sPath & "schema.ini" For Output Access Write As #Handle
         ' -----------------------------------------------
         ' Write schema header.
         ' -----------------------------------------------
         Print #Handle, "[" & sSectionName & "]"
         Print #Handle, "ColNameHeader = " & _
                         IIf(bIncFldNames, "True", "False")
         Print #Handle, "CharacterSet = ANSI"
         Print #Handle, "Format = TabDelimited"
         ' -----------------------------------------------
         ' Get data concerning schema file.
         ' -----------------------------------------------
         Set tblDef = db.TableDefs(sTblQryName)
         With tblDef
            For i = 0 To .Fields.Count - 1
               Set fldDef = .Fields(i)
               With fldDef
                  fldName = .Name
                  Select Case .Type
                     Case dbBoolean
                        fldDataInfo = "Bit"
                     Case dbByte
                        fldDataInfo = "Byte"
                     Case dbInteger
                        fldDataInfo = "Short"
                     Case dbLong
                        fldDataInfo = "Integer"
                     Case dbCurrency
                        fldDataInfo = "Currency"
                     Case dbSingle
                        fldDataInfo = "Single"
                     Case dbDouble
                        fldDataInfo = "Double"
                     Case dbDate
                        fldDataInfo = "Date"
                     Case dbText
                        fldDataInfo = "Char Width " & Format$(.Size)
                     Case dbLongBinary
                        fldDataInfo = "OLE"
                     Case dbMemo
                        fldDataInfo = "LongChar"
                     Case dbGUID
                        fldDataInfo = "Char Width 16"
                  End Select
                  Print #Handle, "Col" & Format$(i + 1) _
                                  & "=" & fldName & Space$(1) _
                                  & fldDataInfo
               End With
            Next i
         End With
         MsgBox sPath & "SCHEMA.INI has been created."
         CreateSchemaFile = True
         Close Handle
         Exit Function
         Msg = "Error #: " & Format$(Err.Number) & vbCrLf
         Msg = Msg & Err.Description
         MsgBox Msg
         Resume CreateSchemaFile_End
End Function


this is my code:

If CreateSchemaFile(True, Mid(fileName, 1, InStrRev(fileName, "\")), Mid(fileName, InStrRev(fileName, "\") + 1), "tempSubTestScoresExp") Then
            DoCmd.TransferText acExportDelim, , "tempSubTestScoresExp", fileName, True, ""
            CurrentDb.TableDefs.Delete "tempSubTestScoresExp"
            MsgBox ("File export complete")
End If

fileName is a global string variable with the path to the export file.  
The code works, but when I look at my export file the first line(field names) is tab delimited with quotes around the field names, which is what I want, except for the quotes.  however, all the data on subsequent lines is embedded in quotes and comma delimited.  I don't know what is going on....I thought using the schema.ini would have given me flexibility to have a tab delimited export file without quotes.  Can anyone shed light on this for me.  I am increasing the points!
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
requisiteSystem - Looks like you've received some solid advice from multiple experts.  Since this question appears to be getting old, please consider awarding points for the effort and closing it.  Thanks in advance.  -Jim
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Routinet:  You are an cleanup volunteer machine today...  :)
Steve BinkCommented:
Yeah, I actually time to spare!  I keep looking around for something else I SHOULD be doing, remember there isn't anything, then go to the next question.  :)  I knew there was a reason for holidays besides more commercials...
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
I think that every once in awhile, but there's always billable hours to be had...  
All Courses

From novice to tech pro — start learning today.