Link to home
Start Free TrialLog in
Avatar of pharries
pharries

asked on

Spot the error

I thinkk there is something wrong with my loops.
This is an access module


Public Function chapter_outputfinal_Gill()

    Dim d As Database
     Dim r As Recordset
     Dim fNum As Integer
     Dim i As Integer

     Set d = CurrentDb
     Set r = d.OpenRecordset("final_gill")

     Do Until r.EOF

          fNum = FreeFile
          i = i + 1
         
Open "f:\gill\" & r!book_ & "\" & r!book_ & "_" & r!ch & ".htm" For Output As fNum


Open "g:\Gill\" & r!bk & "\" & r!bk & "_" & r!ch & ".htm" For Input As #2


              Do While Not EOF(2)
              Line Input #2, MyString
              Print #fNum, MyString
              Loop
     Close #2
     Close fNum
     r.MoveNext
           
     Loop

     Set r = Nothing
     Set d = Nothing


End Function


ASKER CERTIFIED SOLUTION
Avatar of wpsjr1
wpsjr1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sbmc
sbmc

Also instead of #2 use fnum2. After your first open

fnum2=freefile
A little housekeeping for ya.. and a couple of enhancements / corrections.. <smile>

<----- Code Begin ----->

Public Function chapter_outputfinal_Gill()

   Dim db As Database
   Dim rs As Recordset
   Dim intFile1 As Integer
   Dim strFile1 As String
   Dim intFile2 As Integer
   Dim strFile2 As String
   Dim strWork As String
   
   intFile1 = FreeFile
   intFile2 = FreeFile
   
   Set db = CurrentDb
   Set rs = db.OpenRecordset("final_gill")
   
   Do Until rs.EOF
       
      strFile1 = "f:\gill\" _
         & r!book & "\" _
         & r!book & "_" & r!ch _
         & ".htm"
      Open strFile1 For Append As intFile1
     
      strFile2 = "g:\Gill\" _
         & r!bk & "\" _
         & r!bk & "_" & r!ch _
         & ".htm"
      Open strFile2 For Binary As intFile2
     
      strWork = Space(LOF(intFile2))
      Get intFile2, , strWork
      Put intFile1, , strWork
     
      Close intFile1
      Close intFile2
     
      rs.MoveNext
         
   Loop

   rs.Close
   Set rs = Nothing
   Set db = Nothing
   
End Function

<----- Code End ----->
Avatar of pharries

ASKER

Sorry the script was fine
I was just looking in the wrong place!