Pages

Wednesday, December 28, 2011

Export Table To Txt File With Pipe Sign Delimit and Text Qualifier Single Quote

If you want to export the table to text file with delimit sign "|" and text qualifier single quote.

Here is the code-


Sub export_table_to_text_file_with_delimit_pipe()
Dim rs As Recordset
MyFile = "C:\Users\ashishkoul\Desktop\learn\sample_file.txt"
'set and open file for output
fnum = FreeFile()
Set rs = CurrentDb.OpenRecordset("SALES_DETAIL", dbOpenDynaset)
Open MyFile For Output As fnum
rs.MoveFirst
Do While Not rs.EOF
' you can change the text qualifier and delimit sign as per your requirement
' using | as seperator in fields
' USED ' as text qualifier
Print #fnum, rs.Fields![Rep ID].Value & "|" & "'" & rs.Fields![Rep name].Value & "'" & "|" & "'" & rs.Fields![STATE].Value & "'" & "|" & "'" & rs.Fields![Location].Value & "'" & "|" & rs.Fields![sales].Value
rs.MoveNext
Loop
rs.Close
Close #fnum
End Sub

Download Access Database

No comments:

Post a Comment