Export to new .txt file everytime

  • Thread starter James G via AccessMonster.com
  • Start date
J

James G via AccessMonster.com

Hi.....i have a temporary table......this table has 5 fields in it.....what
iam trying to do is export this table to my local hard drive as a .txt file...
....and each time that i click the button to export the table it will name the
txt file a differnt name according to my primary key........for instance......
...Primary Key = 234......txt file=000234...........this works fine......but
there is one problem.....how do i incorporate my export specifications with
my code below?....and also......how to i export the formats?.....because most
of the fields i am exporting will be currecy fields.....if you need any more
info let me know.....thanks...


Private Sub Command12_Click()

Dim rst As DAO.Recordset
Dim FolderName As String
Dim FileName As String

FolderName = "D:\Documents\eWorksheetForOSG\Export"
Set rst = CurrentDb.OpenRecordset("tOSG_Connect_Temp")
rst.MoveFirst
Do Until rst.EOF
FileName = FolderName & "\000" & rst.Fields(0) & ".txt"
Open FileName For Output As #1
Print #1, rst.Fields(0), rst.Fields(1), rst.Fields(2), rst.Fields(3), rst.
Fields(4)
Close #1
rst.MoveNext
Loop
rst.Close
Set rst = Nothing

End Sub
 
O

Ofer

Try the format with zero's in the desire length

FolderName & format(rst.Fields(0),"0000000") & ".txt"
 
O

Ofer

No, then you should use TransferSpreadsheet
docmd.TransferSpreadsheet acExport,acSpreadsheetTypeExcel7,"TableqQueryName"
,"FileName"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top