Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TransferText 1

Status
Not open for further replies.

Ouch

Programmer
Jul 17, 2001
159
GB
i am using the transfer text method to export a text file

DoCmd.TransferText_acExportDelim, , "qry_output", "C:\externals.txt"

it give me an output as shown

"ext_huckerch","Huckerby","Cheryl","2588178"

i want to have

ext_huckerch,Huckerby,Cheryl,2588178

it apparebtly can be done using the specification name but i have no idea how to go about this

can anyone help?
 
I'm not sure about using specifications for exporting, I always use this function:
Function TransferDelimText(rst As DAO.Recordset, Delim As String, FileName As String, Optional Fieldnames As Boolean = True)
Dim f As Integer
Dim strLine As String
Dim fld As DAO.Field
On Error GoTo CloseAndExit
f = FreeFile
Open FileName For Output As f

If Fieldnames = True Then
For Each fld In rst.Fields
strLine = strLine & fld.Name & Delim
Next fld
strLine = Left(strLine, Len(strLine) - Len(Delim))
Print #f, strLine
End If

Do Until rst.EOF
strLine = ""
For Each fld In rst.Fields
strLine = strLine & rst(fld.Name) & Delim
Next fld
strLine = Left(strLine, Len(strLine) - Len(Delim))
Print #f, strLine
rst.MoveNext
Loop

CloseAndExit:
Close #f
End Function

Sub Demo()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblImport")
TransferDelimText rs, ",", "C:\Import.txt"
rs.Close
Set rs = Nothing
End Sub

Call it like in the Sub Demo() changing the variables to match your situation. You don't have to pass a table with the open recordset, it can be a table, a query or even a raw SQL string.

Hope this helps.

B ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
The easiest way to create a specification name is to to export the table manually the first time.
1. Using the export wizard, do a save-as
2. Select the "Advanced" button
3. Deselect the " as the text qualifier
4. Using the "Save As", name your specification (i.e. TestExport)
5. Finish the procedure until you have completed the export
6. Add in your new specification, DoCmd.TransferText_acExportDelim, "TestExport", "qry_output", "C:\externals.txt"

Hope this helps,
Rory
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top