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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import Text (txt) file to Access

Status
Not open for further replies.

adamctb

Programmer
Jun 27, 2006
4
GB
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 = fso_OpenTextFile(strFile, 1) '1=ForReading
strContent = f.ReadAll
f.Close

Set f = fso_OpenTextFile(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
 
Ok my mistake the code does not work in VB6 either - that explains a few things, will look into tomorrow.
 
Lot's of examples in forum705 search for txt.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top