Hi,
I have to import a number of 60MB - 70MB txt files into an access table, which works fine. However before importing I would like to remove the first 7 lines of the text.
I have had to do a similar thing in the past but with much smaller files and in VB6 using the below code:
Private Function FooBar()
Dim Counter
Counter = 7
While Counter > 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fspenTextFile(strFile, 1) '1=ForReading
strContent = f.ReadAll
f.Close
Set f = fspenTextFile(strFile, 2, True) '2=ForWriting
f.Write Mid(strContent, InStr(strContent, vbCrLf) + 2)
f.Close
Counter = Counter - 1
Wend
End Function
When using this code in Access VBA i receive the following error:
Run-time error '-2147417848 (80010108)':
Method 'ReadAll' of object 'ITextStream' failed
The code does work fine in VB6 though - this is the first time I've had to really use VBA so not much experience. Even though the code works fine in VB6 this method is very slow due to the file size, it can take approx 8mins to remove the first 7 lines of a single 60MB file.
So, if anyone can provide me with a solution to why this method failes in VBA that would be great. If you can suggest a quicker method of removing the first 7 lines the even better!
Many Thanks,
Adam
I have to import a number of 60MB - 70MB txt files into an access table, which works fine. However before importing I would like to remove the first 7 lines of the text.
I have had to do a similar thing in the past but with much smaller files and in VB6 using the below code:
Private Function FooBar()
Dim Counter
Counter = 7
While Counter > 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fspenTextFile(strFile, 1) '1=ForReading
strContent = f.ReadAll
f.Close
Set f = fspenTextFile(strFile, 2, True) '2=ForWriting
f.Write Mid(strContent, InStr(strContent, vbCrLf) + 2)
f.Close
Counter = Counter - 1
Wend
End Function
When using this code in Access VBA i receive the following error:
Run-time error '-2147417848 (80010108)':
Method 'ReadAll' of object 'ITextStream' failed
The code does work fine in VB6 though - this is the first time I've had to really use VBA so not much experience. Even though the code works fine in VB6 this method is very slow due to the file size, it can take approx 8mins to remove the first 7 lines of a single 60MB file.
So, if anyone can provide me with a solution to why this method failes in VBA that would be great. If you can suggest a quicker method of removing the first 7 lines the even better!
Many Thanks,
Adam