Here is another option...
Code:Private Sub BuildLogFile2() 'This uses a Temp File to save log info 'and then appends the temp file to the new log file. Dim strFile1 As String Dim strFile2 As String Dim strTemp As String Dim intNum1 As Integer Dim intNum2 As Integer strFile1 = "C:\My Documents\MyFile.log" strFile2 = "C:\My Documents\~MyFileLog.bak" 'Do Clean up before processing 'Use Resume Next in case file doesn't exists On Error Resume Next Kill strFile2 'Now use Error Handler Routine On Error GoTo errHandler intNum1 = FreeFile 'Back Up the Log File (Just to be safe) Name strFile1 As strFile2 'Create New Log File Open strFile1 For Output As intNum1 Print #intNum1, "New Line " & Now Close intNum1 DoEvents 'Append Old Log File to New Log File Open strFile1 For Append As intNum1 intNum2 = FreeFile Open strFile2 For Input As intNum2 Do Until EOF(intNum2) Line Input #intNum2, strTemp Print #intNum1, strTemp Loop Close intNum2 Close intNum1 'Clean Up Kill strFile2 Exit Sub errHandler: 'An Error occurred so set things back the way they were Close intNum2 Close intNum1 Kill strFile1 Name strFile2 As strFile1 MsgBox Err.Description, vbOKOnly, "Error " & Err.Number End Sub




Reply With Quote