Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Spot the error

Posted on 2000-03-28
4
148 Views
Last Modified: 2010-05-02
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


0
Comment
Question by:pharries
4 Comments
 
LVL 3

Accepted Solution

by:
wpsjr1 earned 50 total points
ID: 2665756
Move Close #2 and Close fNum  outside of the Loop.

Enjoy!  :)

Paul

http://www.syix.com/wpsjr1/index.html
0
 
LVL 2

Expert Comment

by:sbmc
ID: 2665809
Also instead of #2 use fnum2. After your first open

fnum2=freefile
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2666084
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 ----->
0
 

Author Comment

by:pharries
ID: 2669588
Sorry the script was fine
I was just looking in the wrong place!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question