Snowflake68
Registered User.
- Local time
- Today, 12:28
- Joined
- May 28, 2014
- Messages
- 464
How do I remove the blank line from the end of the text file that this function is creating. The text file is created using the Docmd.TransferText method and then calls this function which opens the text file and inserts a header line at the top of the file but in doing so it is creating an extra line at the end of the file which I need removing.
Code:
Public Function InsertHeader_CS()
'Insert Header line into Text File
Dim strFilePath As String
Dim strFileDate As String
strFilePath = [Application].[CurrentProject].[Path]
strFileDate = Format(Now(), "yyyy_mm_dd_hhnn")
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath & "\Export_CS" & strFileDate & ".txt", ForReading)
strContents = objFile.ReadAll
objFile.Close
strHeaderLine = DLookup("[Header]", "[tbl_HeaderLine]")
strNewContents = strHeaderLine & vbCrLf & strContents
Set objFile = objFSO.OpenTextFile(strFilePath & "\Export_CS" & strFileDate & ".txt", ForWriting)
objFile.WriteLine strNewContents
objFile.Close
End Function