vba error 62 - please help

A

Aaron

Upfront "Big thank you for any help"

'VBA Procedure
Private Sub RunReportCommandButton_Click()

' Set up to write temporary report file to MyDocs
Dim wshShell, vTempFile, vMyDocs
Set wshShell = CreateObject("WScript.Shell")
vMyDocs = wshShell.SpecialFolders("MyDocuments")
vTempFile = vMyDocs & "\file_temp.csv"

' Open report file for input

Open "c:\nmstatus.csv" For Input Shared As #1

' Open temporary file for output
Open vTempFile For Output Shared As #2

Do While Not EOF(1)

Input #1, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, _
v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, _
v21, v22, v23, v24, v25, vPhone, v27, v28, v29, v30, _
v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, _
v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, _
v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, _
v61, v62, v63, v64, v65, v66, v67, v68, v69, v70, _
v71, v72, v73, v74, v75, v76, v77, vPhone1, v79, v80, _
v81, v82, vPhone2, v84, v85, v86, v87, vPhone3, v89, v90, _
v91, v92, v93, v94, v95, v96, v97, v98, v99, v100, _
v111, v112, v113, v114, v115, v116, v117, v118, v119, v120, _
v121, v122, v123, v124, v125, v126, v127, v128

' Get good phone number (if vPhone blank, get vPhone1 etc.
If vPhone = "" Then vPhone = vPhone1
If vPhone = "" Then vPhone = vPhone2
If vPhone = "" Then vPhone = vPhone3
If vPhone = "" Then vPhone = "NA"

' Some phone numbers include the area code, so clean that up.
vPhone = Right(vPhone, 8)

' Write file with edits
Write #2, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, _
v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, _
v21, v22, v23, v24, v25, vPhone, v27, v28, v29, v30, _
v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, _
v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, _
v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, _
v61, v62, v63, v64, v65, v66, v67, v68, v69, v70, _
v71, v72, v73, v74, v75, v76, v77, vPhone1, v79, v80, _
v81, v82, vPhone2, v84, v85, v86, v87, vPhone3, v89, v90, _
v91, v92, v93, v94, v95, v96, v97, v98, v99, v100, _
v111, v112, v113, v114, v115, v116, v117, v118, v119, v120, _
v121, v122, v123, v124, v125, v126, v127, v128
Loop

Close #1
Close #2


' Perform mail merge
ActiveDocument.MailMerge.OpenDataSource Name:=vTempFile, _
ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="", SQLStatement:="", SQLStatement1:=""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With


' Format report headers
' Add headers to first page
Application.Run MacroName:="Macro1"

' Get number of pages in the report
vPageCount = ActiveDocument.Content.ComputeStatistics(wdStatisticPages)

' Add headers to the rest of the report pages
For i = 2 To vPageCount
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Application.Run MacroName:="Macro1"
Next i

' Go to the top of the report
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"

' Close Document1
Windows(2).Activate
ActiveDocument.Close (wdDoNotSaveChanges)

' Delete temporary files

' Pause a few seconds to make sure document is closed properly
' before deleting temp files
Dim PauseTime, Start, Finish, TotalTime
PauseTime = 2
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop

Kill (vTempFile)

End
End Sub

'
comma-delimted text file headers which has ~200 records under it (not posted)
'
NameID,FullName,FullNameWithSalutations,FullNameWithSalutationsAndNoTitles,Title,FirstName,LastName,Suffix,Salutation/Greeting,SearchID,AddressType,AddressLine1,AddressLine2,AddressLine3,AddressLine4,AddressLine5,City,State,PostalCode,DPBC,Carrier,Foreign,Location,PhoneType,PhoneAreaCode,Phone,Extension,Unlisted,Gender,BirthDate,Age,SocialSecurity#,Envelope#,NextYearEnvelope#,MaritalStatus,MailStatus,FamilyPosition,HHType,DifferentLastName,EmailAddress,WebAddress,WhenSetupGlobaFILE,WhoSetupGlobaFILE,WhenUpdatedGlobaFILE,WhoUpdatedGlobaFILE,AdditionalCommentsGB,WebViewPassword,StartOfIndividualInformation,Auxiliary
#,How_Received,Date_Received,Relationship,PledgeWithSpouse,IncludeOnEnvelopeDiskette,PrintStatements,RecordStatus,Module,How
Removed,StatementFrequency,WhenSetupIndividualInfo,WhoSetupIndividualInfo,WhenUpdatedIndividualInfo,WhoUpdatedIndividualInfo,MemoFromIndividualInfo,Date
1 (Old Receive),Date_Baptized,Letter Received,Letter Sent,Date of Death,Date
Presented,Date 7,Date 8,Date 9,Date
Removed,StartOfProspectInformation,AssignedFamily,MemberOf,Source,LastVisitDate1,LastVisitDate2,LastVisitDate3,LastVisitDate4,LastVisitDate5,FirstVisitDate,StartOfPhoneInformation,PhoneType1,PhoneAreaCode1,Phone#1,Extension1,Unlisted1,PhoneType2,PhoneAreaCode2,Phone#2,Extension2,Unlisted2,PhoneType3,PhoneAreaCode3,Phone#3,Extension3,Unlisted3,StartOfGlobaFILECustomInformation,Spiritual
GiftsTrainingSHBC_101,Spiritual Gifts/Training/Admin/Ldrshp,Spiritual
Gifts/Training/Evangelism,Spiritual Gifts/Training/Exhortation,Spiritual
Gifts/Training/Giving,Spiritual Gifts/Training/Hospitality,Spiritual
Gifts/Training/Mercy,Spiritual Gifts/Training/Ministry,Spiritual
Gifts/Training/NML,Spiritual Gifts/Training/Prophecy,Spiritual
Gifts/Training/School Year,Spiritual Gifts/Training/Service/Helps,Spiritual
Gifts/Training/SG1,Spiritual Gifts/Training/SG1 Score,Spiritual
Gifts/Training/SG2,Spiritual Gifts/Training/SG2 Score,Spiritual
Gifts/Training/SG3,Spiritual Gifts/Training/SG3 Score,Spiritual
Gifts/Training/SGN,Spiritual Gifts/Training/SHBC 101,Spiritual
Gifts/Training/Summer,Spiritual Gifts/Training/Sun AM 1st Svc,Spiritual
Gifts/Training/Sun AM 2nd Svc,Spiritual Gifts/Training/Sun Eve,Spiritual
Gifts/Training/Teaching,Spiritual Gifts/Training/Weekday,Spiritual
Gifts/Training/Weeknight

....
'
Document template for headers and records fill underneath
'
«NameID»
«FullName»
«Phone»
«Age»
«How_Received»
«Date_Received»
If then statement to get «Date_Baptized»
If then statement to get «Needs_Baptism»
If then statement to get «Needs_Class»
 
R

rock

All i can do to help u in this case is tell u that Error 62
corresponds to "Input past end of file" error
 
T

TC

Here's a good way to get help: Post a short question, describing your
environment, describing the problem in english, and providing just the
relevant lines where the problem occurs.

Here's a bad way to [not] get help: Post 50 squintillion lines of code,
with no initial explanation of the problem, & expect everyone to read
down through it, on the off chance you might provide more details at
the bottom.

HTH,
TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top