Creating and Writing to a text file

  • Thread starter Thread starter Tim Schiermeyer
  • Start date Start date
T

Tim Schiermeyer

From: "Tim Schiermeyer" <[email protected]>
Subject: Creating and Writing to a text file
Date: Wednesday, July 16, 2003 3:33 PM

I need to do the following:

Write this to a text file

"Text1 " [field data1] ",text2=" [field data 2] ",text3=" [field data 3]
",text4=" [field data 4] ... etc.. etc

The pass couple of days I have been trying to do this at a high approach for
I thought that this was my only option. I use a DDE interface approach
talking to textpad. At which point I was about an hour from completion a
co-worker sat down with me and pointed out a low level approach that lends
itself without the dependence of Textpad. He said I should use the
CreateTextFile function and the Put instructions.
My question is, is this the best approach, will this work, and potential
road blocks I can't see for my ignorance with work with VBA for about a
week? Please response. I would like full control, therefore low level and no
dependence on other programs.
Thank you
Tim Schiermeyer
Rookie
 
Thanks so much for your help, You will go down in my list of people would
have helped me on this project.
Thank you
Tim Schiermeyer
Andy Cole said:
Tim

I would suggest an even simpler method using the Open, Print and Close
statements within VBA as follows;

Sub OutPutTable(strTable As String)

Dim intFN As Integer
Dim intI As Integer
Dim lngJ As Long
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strLine As String

Set db = CurrentDb
Set rst = db.OpenRecordset(strTable, dbOpenDynaset)
If Not rst.BOF Then
rst.MoveFirst
rst.MoveLast
lngJ = rst.RecordCount
intFN = FreeFile
Open "C:\TestOutput.txt" For Output Lock Read Write As #intFN
rst.MoveFirst
Do
strLine = ""
For intI = 0 To rst.Fields.Count - 1
strLine = strLine & Chr(34) & "Text" & intI + 1 & Chr(34) &
"=" & rst.Fields(intI).Value
If intI < rst.Fields.Count - 1 Then
strLine = strLine & ","
End If
Next intI
Print #intFN, strLine
rst.MoveNext
Loop Until rst.EOF
End If
Close #intFN
rst.Close
Set rst = Nothing

End Sub

HTH

Andy


Tim Schiermeyer said:
From: "Tim Schiermeyer" <[email protected]>
Subject: Creating and Writing to a text file
Date: Wednesday, July 16, 2003 3:33 PM

I need to do the following:

Write this to a text file

"Text1 " [field data1] ",text2=" [field data 2] ",text3=" [field data 3]
",text4=" [field data 4] ... etc.. etc

The pass couple of days I have been trying to do this at a high approach for
I thought that this was my only option. I use a DDE interface approach
talking to textpad. At which point I was about an hour from completion a
co-worker sat down with me and pointed out a low level approach that lends
itself without the dependence of Textpad. He said I should use the
CreateTextFile function and the Put instructions.
My question is, is this the best approach, will this work, and potential
road blocks I can't see for my ignorance with work with VBA for about a
week? Please response. I would like full control, therefore low level
and
no
dependence on other programs.
Thank you
Tim Schiermeyer
Rookie
 
Back
Top