Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2008

Tip: Looking for answers? Try searching our database.

I can't make this dir loop work

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ragtopcaddy - 20 Mar 2008 17:45 GMT
Here's my code:

   strFileName = Dir(strPath & "*.xls")
   Do While strFileName <> vbNullString
       strFullPath = strPath & strFileName
       'Do stuff here
       strFileName = Dir
   Loop

The problem is, the files are skipping around. The filename goes from "0707"
to "0709" and skips "0708". any ideas?

Signature

Bill Reed

"If you can't laugh at yourself, laugh at somebody else"

Douglas J. Steele - 20 Mar 2008 18:00 GMT
The Dir function isn't guaranteed to return the files in any specific order.

When you say it's skipping 0708, does it eventually find it if you keep the
code running?

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Here's my code:
>
[quoted text clipped - 8 lines]
> "0707"
> to "0709" and skips "0708". any ideas?
ragtopcaddy - 20 Mar 2008 18:56 GMT
Douglas,

I'll soon find out!

Thanks for your reply,

>The Dir function isn't guaranteed to return the files in any specific order.
>
[quoted text clipped - 6 lines]
>> "0707"
>> to "0709" and skips "0708". any ideas?

Signature

Bill Reed

"If you can't laugh at yourself, laugh at somebody else"

ragtopcaddy - 20 Mar 2008 19:11 GMT
Doug,

No dice! There are 12 files in the directory, but even with my manually
resetting strFileName on the 1st couple of passes, I only got 6 of them.
Could you please give me a code example of how to do this?

Thanks,

>The Dir function isn't guaranteed to return the files in any specific order.
>
[quoted text clipped - 6 lines]
>> "0707"
>> to "0709" and skips "0708". any ideas?

Signature

Bill Reed

"If you can't laugh at yourself, laugh at somebody else"

Douglas J. Steele - 20 Mar 2008 19:20 GMT
Your code snippet should work: there's no other code that I could give you!

The only change I'd make is to replace

Do While strFileName <> vbNullString

with

Do While Len(strFileName) > 0

Exactly what are you doing in the

' Do stuff here

section?

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Doug,
>
[quoted text clipped - 16 lines]
>>> "0707"
>>> to "0709" and skips "0708". any ideas?
ragtopcaddy - 20 Mar 2008 19:47 GMT
Doug,

I can't for the life of me see how this code could possibly work.

There is no equivalent to ".MoveNext" or "Next strFileName" or anything.

How could it possibly loop through a list of 12 files when there is no
apparent mechanism to do so?

Thanks,

>Your code snippet should work: there's no other code that I could give you!
>
[quoted text clipped - 17 lines]
>>>> "0707"
>>>> to "0709" and skips "0708". any ideas?

Signature

Bill Reed

"If you can't laugh at yourself, laugh at somebody else"

Douglas J. Steele - 20 Mar 2008 21:26 GMT
From the Help file:

"Dir returns the first file name that matches pathname. To get any
additional file names that match pathname, call Dir again with no arguments.
When no more file names match, Dir returns a zero-length string (""). Once a
zero-length string is returned, you must specify pathname in subsequent
calls or an error occurs."

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Doug,
>
[quoted text clipped - 29 lines]
>>>>> "0707"
>>>>> to "0709" and skips "0708". any ideas?
ileana - 22 Mar 2008 18:59 GMT
> Here's my code:
>
[quoted text clipped - 7 lines]
> The problem is, the files are skipping around. The filename goes from "0707"
> to "0709" and skips "0708". any ideas?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.