Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write data into a file

Status
Not open for further replies.

AKarim

Technical User
Mar 20, 2000
41
EU
Hi,<br>I'm trying to write datas into an existing text file, but i want the new data to go at the bigining of the file without loosing the other datas.<br><br>How must i open the file, & how to write:<br>here is my code<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim fHistorique As Integer<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'Ouverture du fichier<br>&nbsp;&nbsp;&nbsp;&nbsp;On Error GoTo LoadError<br>&nbsp;&nbsp;&nbsp;&nbsp;fHistorique = FreeFile<br>&nbsp;&nbsp;&nbsp;&nbsp;'Open cCheminHistorique For Output As fHistorique<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Write #fHistorique, EntrantSortant & &quot; &quot; & Tag & &quot; &quot; & DateHeure & &quot; - &quot; & Text<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Fermeture du fichier<br>&nbsp;&nbsp;&nbsp;&nbsp;Close fHistorique<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>LoadError:<br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Erreur &quot; & Str$(Err.Number) & _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot; pendant l'enregistrement de l'historique :&quot; & vbCrLf & _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Err.Description<br>----<br>thxs<br>
 
I don't know of any direct way to 'append' to the beginning of a file.&nbsp;&nbsp;You could open a new file for Output, write your new data to it, then open your old data file for Input, read the data in from it and Append it to the new file. Kill the old file, and rename the new file to the same name as the old one.&nbsp;&nbsp;It sounds like more work than it really is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top