Export to text file

24sharon

Registered User.
Local time
Today, 13:40
Joined
Oct 5, 2004
Messages
147
Hello,

I have a text file “c:/123.001”

And I have a string.
For Example:

strString = “ 123 “ & chr(34) & vbcrlf & “4567 “
strString =strString & vbcrlf & “its Example “

And I want to replace the text file – to delete the old string and put the new.

I search this forum and I found just export tables but not strings.

Thanks for any answer or link.

Good day!
S.

<I attach a text file like the text that I need>
 

Attachments

Last edited:
Open a form in design mode, view code, then click on help, ask it for

OpenAsTextStream method


Study this:

The OpenAsTextStream method provides the same functionality as the OpenTextFile method of the FileSystemObject. In addition, the OpenAsTextStream method can be used to write to a file.

The following code illustrates the use of the OpenAsTextStream method:

Sub TextStreamTest
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CreateTextFile "test1.txt" 'Create a file
Set f = fs.GetFile("test1.txt")
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
ts.Write "Hello World"
ts.Close
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
s = ts.ReadLine
MsgBox s
ts.Close
End Sub
 
Liv Manto

thanks for your time...

I found this file and it do my work
Code:
Private Sub Command0_Click()

Dim db As Database, rst As Recordset
Dim qdf As QueryDef
Dim Directory As String
Dim MyString As String, strSQL As String
Set db = CurrentDb
Open "C:\Msv.001" For Output As #1
Set rst = db.OpenRecordset("masavKOT")

Print #1, "This is where header information would go if needed"
rst.MoveFirst
Do While Not rst.EOF
    MyString = rst!mosad & rst!Filler1 
    Print #1, MyString
    rst.MoveNext
Loop
Print #1, "LAST ROW"

    Close #1
    rst.Close
    Set db = Nothing
    End Sub
 

Users who are viewing this thread

Back
Top Bottom