If you want to append the data of access table to already existing text file.
Here is the code-
Sub append_the_data_to_already_created_text_file()
Dim rs As Recordset
' sales deatil is the table name
Set rs = CurrentDb.OpenRecordset("SALES_DETAIL", dbOpenDynaset)
MyFile = "C:\Users\ashishkoul\Desktop\learn\sample_file.txt"
'set and open file for output
fnum = FreeFile()
Open MyFile For Append As #1
Write #1,
rs.MoveFirst
Do While Not rs.EOF
' 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