PC Review


Reply
Thread Tools Rate Thread

How do I Stop a Continuous Loop?

 
 
Bob
Guest
Posts: n/a
 
      30th Jun 2004
The below code imports data from text files into a
database. Unfortunately, the loop does not end and just
keeps importing the data over and over and over again.
Does anyone have any suggestions?

Private Sub Command11_Click()

Dim myfile
Dim mypath
mypath = "C:\Documents and Settings\u26g\My
Documents\reusability\"
Do
myfile = Dir(mypath & "*.txt")
'this will import ALL the text files (one at a time, but
automatically) in this folder.
DoCmd.TransferText
acImportDelim, "Tab_Spec", "Resuability_test", mypath &
myfile
myfile = Dir
Loop Until myfile = ""

End Sub
 
Reply With Quote
 
 
 
 
Rick Brandt
Guest
Posts: n/a
 
      30th Jun 2004
"Bob" <(E-Mail Removed)> wrote in message
news:23b6001c45ed9$fda5c430$(E-Mail Removed)...
> The below code imports data from text files into a
> database. Unfortunately, the loop does not end and just
> keeps importing the data over and over and over again.
> Does anyone have any suggestions?
>
> Private Sub Command11_Click()
>
> Dim myfile
> Dim mypath
> mypath = "C:\Documents and Settings\u26g\My
> Documents\reusability\"
> Do
> myfile = Dir(mypath & "*.txt")

[snip]

The first Dir() call above has to be outside your Do Loop. Otherwise you
are just resetting it to the first text file over and over again.


--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


 
Reply With Quote
 
solex
Guest
Posts: n/a
 
      30th Jun 2004
Private Sub Command11_Click()

Dim myfile
Dim mypath

mypath = "C:\Documents and Settings\u26g\My Documents\reusability\"
myfile = Dir(mypath & "*.txt")

Do
myfile = Dir()
'this will import ALL the text files (one at a time, but
automatically) in this folder.
DoCmd.TransferText
acImportDelim, "Tab_Spec", "Resuability_test", mypath & myfile
myfile = Dir
Loop Until myfile = ""

End Sub

"Bob" <(E-Mail Removed)> wrote in message
news:23b6001c45ed9$fda5c430$(E-Mail Removed)...
> The below code imports data from text files into a
> database. Unfortunately, the loop does not end and just
> keeps importing the data over and over and over again.
> Does anyone have any suggestions?
>
> Private Sub Command11_Click()
>
> Dim myfile
> Dim mypath
> mypath = "C:\Documents and Settings\u26g\My
> Documents\reusability\"
> Do
> myfile = Dir(mypath & "*.txt")
> 'this will import ALL the text files (one at a time, but
> automatically) in this folder.
> DoCmd.TransferText
> acImportDelim, "Tab_Spec", "Resuability_test", mypath &
> myfile
> myfile = Dir
> Loop Until myfile = ""
>
> End Sub



 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      30th Jun 2004
"solex" <(E-Mail Removed)> wrote in
news:#(E-Mail Removed):

> Do
> myfile = Dir()
>


The two problems with this are that

a) the first return from Dir is thrown away, and
b) the last value will be "", which will cause an error in the rest of the
loop.

The correct order is:

' get the first file here
strMyFile = Dir(Something)

' I always like tests at the top!
Do While True

' body of loop here
DoSomethingWith strMyFile

' now get the next value
strMyFile = Dir()

If Len(strMyFile)=0 Then ' neater than strMyFile=""
' no files left
Exit Do

End If

Loop



Hope that helps


Tim F

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
loop through continuous forms KathyB Microsoft Access Forms 6 17th Jun 2009 05:38 PM
Re: Continuous Loop John Coleman Microsoft Excel Programming 1 22nd Dec 2006 03:11 PM
Continuous Loop gordo Microsoft Powerpoint 2 1st Sep 2006 12:52 AM
Continuous Loop =?Utf-8?B?aW5kaW8=?= Microsoft Powerpoint 3 9th Feb 2005 05:09 PM
Continuous Loop Keith Phelps Microsoft Powerpoint 2 1st Jul 2003 07:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:53 PM.