Modify text file

arage

Registered User.
Local time
Today, 04:28
Joined
Dec 30, 2000
Messages
537
Modify text file
I have never really used dao or recordsets in any of my coding experience but think I am about too. I’ve got my form to the point where I can determine whether a file exists in particular directory and I need to modify this file by opening it (thru code) going to the bottom of the file (last record) & deleting it b/c it is an ENTER character, how might I go about this please?
 
So you want to delete an entire record? In that case I would just use a delete query. Easier to setup.
 
But how do i specify the eof record in the delete query???...i tried placing chr(13) as criteria for all fields but that changes nothing...to help you visualize what i do when i manually make this change....imagine the txt file open...i do ctl+end & then backspace key one time...this is what i need to get rid of....do you consider this chr(13), a carriage return, or what???

thanks for your patience....!
 
Maybe you should use vba.

Dim rst as DAO.Recordset

Set rst=CurrentDB.OpenRecordset("Table Name", DBOpenDynaset)

rst.MoveLast

rst.Delete


This should work.
 
I don't have any example code to post. Look up the Open Statement in help. It will have an example (or its See Also will) of how to open a text file. You can't delete records from text files. In fact the ONLY type of updating you can do to a text file is to append records to the end. Therefore, if you need to add, change, or delete records from a text file, the process is to read the text file using a loop so you process every record and within the loop write to an output text file. In your case you'll want to read every record in the input file and write it to the output file until you come to the record you want to eliminate. When you find that record, don't write it to the output file.

Psuedo code is:

Open file
Read first record
Do While Not EOF
If somecondition Then
Else
write output file
end if
read next record
loop
close output file
 
Arage,


Dim buf1 As String
Dim buf2 As String

Open "C:\Infile1.txt" for Input As #1
Open "C:\Outfile1.txt" for Output As #2

Line Input #1, buf1
While Not EOF(1)
Line Input #2, buf2
If Not EOF(1) Then
Print #2, buf1
buf1 = buf2
End If
Wend

Close #1
Close #2

hth,
Wayne
 

Users who are viewing this thread

Back
Top Bottom