• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5407
  • Last Modified:

Run-time error '62': Input past end of file

Hi all,

The code below used to work just fine, but now it has stopped working and produces the following message: Run-time error '62': Input past end of file

Could you please look into the script and make the necessary amendments?

Thank you :)

Sub Transactions()


Dim strSQL As String
Const ForReading = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oReadFile = oFSO.OpenTextFile("J:\Evaluering_v3.txt", ForReading, True)

strSQL = oReadFile.ReadAll
strSqlDynamisk = strSQL
Set oFSO = Nothing
Dim adoConn As ADODB.Connection
Set adoConn = New ADODB.Connection
adoConn.CommandTimeout = False
adoConn.Open "abc", "def", "efg"
Dim ADOrst As ADODB.Recordset

Set ADOrst = adoConn.Execute(strSqlDynamisk)

Range("a2").CopyFromRecordset ADOrst
Set ADOrst = Nothing
Set adoConn = Nothing
End Sub
1 Solution
Barry CunneyCommented:
Has the format of the J:\Evaluering_v3.txt file changed?
Look for spaces at the end of each line or at the end of the file
Maybe open the file and resave and try again
NorieVBA ExpertCommented:
The code looks fine.

Has anything about the file Evaluering_v3.txt changed?
Martin LissOlder than dirtCommented:
The file probably contains characters like Ascii 255/254 which may be mistaken for end of file. Would it be possible for you to attach the file?
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

UtredningAuthor Commented:
Thanks for looking into this.

Bunney: I did remove one 'space-bar' and saved it again; but it made noe difference.

Imnorie: I have not changed anything about the file since it last time it worked.

MartinLiss/Imnorie/: I have uploaded the script that I use; please look into it to see if there is something in error.

Other than that; is it possible to enhance the vba-code? Like adding a snippet that establishes the end of file? Like EOF-functionality? If so, please include to show me that can be done.

Thanks alot.
Martin LissOlder than dirtCommented:
Try reading the file this way

    Open "C:\temp\Evaluering-v3.txt" For Input As #1
    strSQL = Input$(LOF(1), 1)
UtredningAuthor Commented:
Helpfull in understanding the problem.
UtredningAuthor Commented:
When I relocated the sql-script-file and then ran the snippet given by MartinLiss; then I got no error message and I also got content in the Immediate-window. The solution was simply to move the file to be read to a new loaction. Which is strange because it worked perfectly at its original location.
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now