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()

Sheets("Input").Select

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
oReadFile.Close
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
UtredningAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
0
NorieAnalyst Assistant Commented:
The code looks fine.

Has anything about the file Evaluering_v3.txt changed?
0
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?
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

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.
Evaluering-v3.txt
0
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)
    Close
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UtredningAuthor Commented:
Helpfull in understanding the problem.
0
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.
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.